package com.inei.cie.dao;

import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.inei.cie.entidades.P1_A;
import com.inei.cie.entidades.P1_A_2N;
import com.inei.cie.entidades.P1_A_2_8N;
import com.inei.cie.entidades.P1_A_2_9N;
import com.inei.cie.entidades.P1_B;
import com.inei.cie.entidades.P1_B_2A_N;
import com.inei.cie.entidades.P1_B_3N;
import com.inei.cie.entidades.P1_B_3_12N;
import com.inei.cie.entidades.P1_C;
import com.inei.cie.entidades.P1_C_20N;
import com.inei.cie.entidades.PMod;

public class CapituloIDao {
	private UtilDB util;
	SQLiteDatabase db;
	Cursor cursor = null;
	Context context;

	public CapituloIDao(Context context) {
		this.context = context;
		util = new UtilDB(context);
	}

	public List<String> ListadoModulares(String id_local) {
		List<String> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery("select * from PMod where id_local=?",
				new String[] { id_local + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<String>();
			while (!cursor.isAfterLast()) {
				PMod pmod = new PMod();
				pmod.setCod_mod(cursor.getString(cursor
						.getColumnIndex("cod_mod")));
				lista.add(pmod.getCod_mod());
				cursor.moveToNext();
			}
		}
		Cerrar();
		return lista;
	}

	public P1_A ObtenerSeccionA(String id_local, int PC_F_1) {
		P1_A p1_a = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"Select * from P1_A where id_local=? and PC_F_1=?",
				new String[] { id_local, PC_F_1 + "" });
		if (cursor.moveToFirst()) {
			p1_a = new P1_A();
			p1_a.setId_local(id_local);
			p1_a.setPC_F_1(PC_F_1);
			p1_a.setP1_A_1_Cant_IE(cursor.getInt(cursor
					.getColumnIndex("P1_A_1_Cant_IE")));
			p1_a.setP1_Obs(cursor.getString(cursor.getColumnIndex("P1_Obs")));
			p1_a.setSwCompleto(cursor.getInt(cursor
					.getColumnIndex("SwCompleto")));
			p1_a.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
		}
		Cerrar();
		return p1_a;
	}

	public P1_B ObtenerSeccionB(String id_local) {
		P1_B p1_b = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery("Select * from P1_B where id_local=?",
				new String[] { id_local });
		if (cursor.moveToFirst()) {
			p1_b = new P1_B();
			p1_b.setId_local(id_local);
			p1_b.setP1_B_1_TPred(cursor.getInt(cursor
					.getColumnIndex("P1_B_1_TPred")));
			p1_b.setP1_B_2_PredCol(cursor.getInt(cursor
					.getColumnIndex("P1_B_2_PredCol")));
			p1_b.setSwCompleto(cursor.getInt(cursor
					.getColumnIndex("SwCompleto")));
			p1_b.setVersion(cursor.getColumnIndex("Version"));
		}
		Cerrar();
		return p1_b;
	}

	public List<P1_B_2A_N> ObtenerSeccionB_2N(String id_local) {
		List<P1_B_2A_N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery("Select * from P1_B_2A_N where id_local=?",
				new String[] { id_local });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_B_2A_N>();
			while (!cursor.isAfterLast()) {
				P1_B_2A_N obj = new P1_B_2A_N();
				obj.setId_local(id_local);
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setP1_B_2A_PredNoCol(cursor.getInt(cursor
						.getColumnIndex("P1_B_2A_PredNoCol")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setVersion(cursor.getColumnIndex("Version"));
				obj.setSwEnviado(cursor.getColumnIndex("SwEnviado"));
				lista.add(obj);
				cursor.moveToNext();
			}
		}
		Cerrar();
		return lista;
	}

	public boolean GuardarSeccionAB(P1_A p1_a, P1_B p1_b, List<P1_B_2A_N> lista) {
		try {
			GuardarSeccionA(p1_a);
			GuardarSeccionB(p1_b);
			GuardarSeccionB_2N(lista);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	public void GuardarSeccionA(P1_A p1_a) {
		ContentValues contenido = new ContentValues();
		contenido.put("P1_A_1_Cant_IE", p1_a.getP1_A_1_Cant_IE());
		contenido.put("P1_Obs", p1_a.getP1_Obs());
		contenido.put("SwCompleto", p1_a.getSwCompleto());
		if (ExisteSeccionA(p1_a)) {
			db = util.getWritableDatabase();
			db.update("P1_A", contenido, "id_local=? and PC_F_1=?",
					new String[] { p1_a.getId_local(), p1_a.getPC_F_1() + "" });
			db.close();

			List<P1_A_2N> lista = ObtenerListadoIE(p1_a.getId_local(),
					p1_a.getPC_F_1());
			if (lista.size() < p1_a.getP1_A_1_Cant_IE()) {
				db = util.getWritableDatabase();
				for (int i = lista.size(); i < p1_a.getP1_A_1_Cant_IE(); i++) {
					ContentValues ie = new ContentValues();
					ie.put("id_local", p1_a.getId_local());
					ie.put("PC_F_1", p1_a.getPC_F_1());
					ie.put("P1_A_2_NroIE", i + 1);
					db.insert("P1_A_2N", null, ie);
				}
				db.close();
			} else {
				if (lista.size() > p1_a.getP1_A_1_Cant_IE()) {
					db = util.getWritableDatabase();
					for (int i = p1_a.getP1_A_1_Cant_IE(); i < lista.size(); i++) {
						P1_A_2N obj = lista.get(i);
						db.delete(
								"P1_C",
								"id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
								new String[] { obj.getId_local(),
										obj.getPC_F_1() + "",
										obj.getP1_A_2_NroIE() + "" });
						db.delete(
								"P1_A_2_9N",
								"id_local=? and PC_F_1=?  and P1_A_2_NroIE=?",
								new String[] { obj.getId_local(),
										obj.getPC_F_1() + "",
										obj.getP1_A_2_NroIE() + "" });
						db.delete(
								"P1_A_2_8N",
								"id_local=? and PC_F_1=?  and P1_A_2_NroIE=?",
								new String[] { obj.getId_local(),
										obj.getPC_F_1() + "",
										obj.getP1_A_2_NroIE() + "" });
						db.delete(
								"P1_A_2N",
								"id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
								new String[] { obj.getId_local(),
										obj.getPC_F_1() + "",
										obj.getP1_A_2_NroIE() + "" });
					}
					db.close();
				}
			}
		} else {
			db = util.getWritableDatabase();
			contenido.put("id_local", p1_a.getId_local());
			contenido.put("PC_F_1", p1_a.getPC_F_1());
			db.insert("P1_A", null, contenido);
			for (int i = 0; i < p1_a.getP1_A_1_Cant_IE(); i++) {
				ContentValues ie = new ContentValues();
				ie.put("id_local", p1_a.getId_local());
				ie.put("PC_F_1", p1_a.getPC_F_1());
				ie.put("P1_A_2_NroIE", i + 1);
				db.insert("P1_A_2N", null, ie);
			}
			db.close();
		}
	}

	public boolean ExisteSeccionA(P1_A p1_a) {
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"Select * from P1_A where id_local=? and PC_F_1=?",
				new String[] { p1_a.getId_local(), p1_a.getPC_F_1() + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public void GuardarSeccionB(P1_B p1_b) {
		ContentValues contenido = new ContentValues();
		contenido.put("P1_B_1_TPred", p1_b.getP1_B_1_TPred());
		contenido.put("P1_B_2_PredCol", p1_b.getP1_B_2_PredCol());
		contenido.put("SwCompleto", p1_b.getSwCompleto());
		if (ExisteSeccionB(p1_b)) {
			db = util.getWritableDatabase();
			db.update("P1_B", contenido, "id_local=?",
					new String[] { p1_b.getId_local() });
		} else {
			db = util.getWritableDatabase();
			contenido.put("id_local", p1_b.getId_local());
			db.insert("P1_B", null, contenido);
		}
		db.close();
	}

	public boolean ExisteSeccionB(P1_B p1_b) {
		db = util.getReadableDatabase();
		cursor = db.rawQuery("Select * from P1_B where id_local=?",
				new String[] { p1_b.getId_local() });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public void EliminarDatosPredio(P1_B_2A_N obj) {
		String id_local = obj.getId_local();
		int Nro_Pred = obj.getNro_Pred();
		db.delete("PCar", "id_local=? and PC_F_1=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("PCar_C_1N", "id_local=? and PC_F_1=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P2_A", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P2_B", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P2_B_9N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P2_B_10N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P2_B_11N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P2_B_12N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P2_C", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P2_D", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P2_D_1N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P2_D_5N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P2_D_3N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P2_D_7N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P2_D_9N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P2_E", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P2_F", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P2_G", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P2_G_2N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("PUNTO3", "codigoLocalPadron=? and codigoPredio=?",
				new String[] { id_local, Nro_Pred + "" });
		db.delete("PUNTOS_GPS", "codigoLocalPadron=? and codigoPredio=?",
				new String[] { id_local, Nro_Pred + "" });
		db.delete("FRENTE_LINDEROS", "id_local=? and P4_NroPred=?",
				new String[] { id_local, Nro_Pred + "" });
		db.delete("P4_2N", "id_local=? and P4_NroPred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P5", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P5_N", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P5_F", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P6_1", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P6_1_8N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P6_1_10N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P6_2", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P6_2_4N", "id_local=? and Nro_Pred=?", new String[] {
				id_local, Nro_Pred + "" });
		db.delete("P7", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P8", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
		db.delete("P9_F", "id_local=? and Nro_Pred=?", new String[] { id_local,
				Nro_Pred + "" });
	}

	public void GuardarSeccionB_2N(List<P1_B_2A_N> lista) {
		List<P1_B_2A_N> lista1 = ObtenerSeccionB_2N(lista.get(0).getId_local());

		db = util.getWritableDatabase();
		if (lista1 != null) {
			if (lista1 != lista) {

				if (lista1.size() == lista.size()) {
					for (int i = 0; i < lista.size(); i++) {
						if (lista1.get(i).getP1_B_2A_PredNoCol() != lista
								.get(i).getP1_B_2A_PredNoCol()) {
							ContentValues contenido = new ContentValues();
							contenido.put("P1_B_2A_PredNoCol", lista.get(i)
									.getP1_B_2A_PredNoCol());
							db.update("P1_B_2A_N", contenido,
									"id_local=? and Nro_Pred=?", new String[] {
											lista.get(i).getId_local(),
											lista.get(i).getNro_Pred() + "" });
							if (lista.get(i).getP1_B_2A_PredNoCol() == 0) {
								EliminarDatosPredio(lista.get(i));
							}
						}
					}
				} else if (lista1.size() < lista.size()) {
					for (int i = 0; i < lista1.size(); i++) {
						if (lista1.get(i).getP1_B_2A_PredNoCol() != lista
								.get(i).getP1_B_2A_PredNoCol()) {
							ContentValues contenido = new ContentValues();
							contenido.put("P1_B_2A_PredNoCol", lista.get(i)
									.getP1_B_2A_PredNoCol());
							db.update("P1_B_2A_N", contenido,
									"id_local=? and Nro_Pred=?", new String[] {
											lista.get(i).getId_local(),
											lista.get(i).getNro_Pred() + "" });
							if (lista.get(i).getP1_B_2A_PredNoCol() == 0) {
								EliminarDatosPredio(lista.get(i));
							}
						}
					}
					for (int i = lista1.size(); i < lista.size(); i++) {

						ContentValues contenido = new ContentValues();
						contenido.put("id_local", lista.get(i).getId_local());
						contenido.put("Nro_Pred", lista.get(i).getNro_Pred());
						contenido.put("P1_B_2A_PredNoCol", lista.get(i)
								.getP1_B_2A_PredNoCol());
						db.insert("P1_B_2A_N", null, contenido);

					}
				}
			}
		} else {
			for (int i = 0; i < lista.size(); i++) {
				ContentValues contenido = new ContentValues();
				contenido.put("id_local", lista.get(i).getId_local());
				contenido.put("Nro_Pred", lista.get(i).getNro_Pred());
				contenido.put("P1_B_2A_PredNoCol", lista.get(i)
						.getP1_B_2A_PredNoCol());
				db.insert("P1_B_2A_N", null, contenido);

			}

		}

		db.close();
	}

	public boolean ExisteSeccionB_2N(P1_B_2A_N obj) {
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"Select * from P1_B_2A_N where id_local=? and Nro_Pred=?",
				new String[] { obj.getId_local(), obj.getNro_Pred() + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public P1_B_3N ObtenerPredio(String id_local, int Nro_Pred) {
		P1_B_3N obj = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"Select * from P1_B_3N where id_local=? and Nro_Pred=?",
				new String[] { id_local, Nro_Pred + "" });
		if (cursor.moveToFirst()) {
			obj = new P1_B_3N();
			obj.setId_local(id_local);
			obj.setNro_Pred(Nro_Pred);
			obj.setP1_B_3_InmCod(cursor.getString(cursor
					.getColumnIndex("P1_B_3_InmCod")));
			obj.setP1_B_3_InmTip(cursor.getInt(cursor
					.getColumnIndex("P1_B_3_InmTip")));
			obj.setP1_B_3_1_Prop(cursor.getInt(cursor
					.getColumnIndex("P1_B_3_1_Prop")));
			obj.setP1_B_3_1_Prop_O(cursor.getString(cursor
					.getColumnIndex("P1_B_3_1_Prop_O")));
			obj.setP1_B_3_2_AntReg_Cod(cursor.getInt(cursor
					.getColumnIndex("P1_B_3_2_AntReg_Cod")));
			obj.setP1_B_3_3_AntReg_Nro(cursor.getString(cursor
					.getColumnIndex("P1_B_3_3_AntReg_Nro")));
			obj.setP1_B_3_4_Tipo_TProp(cursor.getInt(cursor
					.getColumnIndex("P1_B_3_4_Tipo_TProp")));
			obj.setP1_B_3_4_Tipo_TProp_O(cursor.getString(cursor
					.getColumnIndex("P1_B_3_4_Tipo_TProp_O")));
			obj.setP1_B_3_5_FecTit(cursor.getString(cursor
					.getColumnIndex("P1_B_3_5_FecTit")));
			obj.setP1_B_3_6_DocPos(cursor.getInt(cursor
					.getColumnIndex("P1_B_3_6_DocPos")));
			obj.setP1_B_3_6_DocPos_O(cursor.getString(cursor
					.getColumnIndex("P1_B_3_6_DocPos_O")));
			obj.setP1_B_3_7_DocPos_Fech(cursor.getString(cursor
					.getColumnIndex("P1_B_3_7_DocPos_Fech")));
			obj.setP1_B_3_8_Tip_At_Pred(cursor.getInt(cursor
					.getColumnIndex("P1_B_3_8_Tip_At_Pred")));
			obj.setP1_B_3_8_At_Pred(cursor.getFloat(cursor
					.getColumnIndex("P1_B_3_8_At_Pred")));
			obj.setP1_B_3_9_Tip_At_Local(cursor.getInt(cursor
					.getColumnIndex("P1_B_3_9_Tip_At_Local")));
			obj.setP1_B_3_9_At_Local(cursor.getFloat(cursor
					.getColumnIndex("P1_B_3_9_At_Local")));
			obj.setP1_B_3_10_Comp(cursor.getInt(cursor
					.getColumnIndex("P1_B_3_10_Comp")));
			obj.setP1_B_3_11_CompCan(cursor.getInt(cursor
					.getColumnIndex("P1_B_3_11_CompCan")));
			obj.setP1_B_3_Obs(cursor.getString(cursor
					.getColumnIndex("P1_B_3_Obs")));
			obj.setSwCompleto(cursor.getInt(cursor.getColumnIndex("SwCompleto")));
			obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
		}
		Cerrar();
		return obj;
	}

	public List<P1_B_3N> ObtenerPredios(String id_local) {
		List<P1_B_3N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery("Select * from P1_B_3N where id_local=?",
				new String[] { id_local });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_B_3N>();
			while (!cursor.isAfterLast()) {
				P1_B_3N obj = new P1_B_3N();
				obj.setId_local(id_local);
				obj.setNro_Pred(cursor.getInt(cursor.getColumnIndex("Nro_Pred")));
				obj.setP1_B_3_InmCod(cursor.getString(cursor
						.getColumnIndex("P1_B_3_InmCod")));
				obj.setP1_B_3_InmTip(cursor.getInt(cursor
						.getColumnIndex("P1_B_3_InmTip")));
				obj.setP1_B_3_1_Prop(cursor.getInt(cursor
						.getColumnIndex("P1_B_3_1_Prop")));
				obj.setP1_B_3_1_Prop_O(cursor.getString(cursor
						.getColumnIndex("P1_B_3_1_Prop_O")));
				obj.setP1_B_3_2_AntReg_Cod(cursor.getInt(cursor
						.getColumnIndex("P1_B_3_2_AntReg_Cod")));
				obj.setP1_B_3_3_AntReg_Nro(cursor.getString(cursor
						.getColumnIndex("P1_B_3_3_AntReg_Nro")));
				obj.setP1_B_3_4_Tipo_TProp(cursor.getInt(cursor
						.getColumnIndex("P1_B_3_4_Tipo_TProp")));
				obj.setP1_B_3_4_Tipo_TProp_O(cursor.getString(cursor
						.getColumnIndex("P1_B_3_4_Tipo_TProp_O")));
				obj.setP1_B_3_5_FecTit(cursor.getString(cursor
						.getColumnIndex("P1_B_3_5_FecTit")));
				obj.setP1_B_3_6_DocPos(cursor.getInt(cursor
						.getColumnIndex("P1_B_3_6_DocPos")));
				obj.setP1_B_3_6_DocPos_O(cursor.getString(cursor
						.getColumnIndex("P1_B_3_6_DocPos_O")));
				obj.setP1_B_3_7_DocPos_Fech(cursor.getString(cursor
						.getColumnIndex("P1_B_3_7_DocPos_Fech")));
				obj.setP1_B_3_8_At_Pred(cursor.getFloat(cursor
						.getColumnIndex("P1_B_3_8_At_Pred")));
				obj.setP1_B_3_9_At_Local(cursor.getFloat(cursor
						.getColumnIndex("P1_B_3_9_At_Local")));
				obj.setP1_B_3_10_Comp(cursor.getInt(cursor
						.getColumnIndex("P1_B_3_10_Comp")));
				obj.setP1_B_3_11_CompCan(cursor.getInt(cursor
						.getColumnIndex("P1_B_3_11_CompCan")));
				obj.setP1_B_3_Obs(cursor.getString(cursor
						.getColumnIndex("P1_B_3_Obs")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		}
		Cerrar();
		return lista;
	}

	public List<P1_B_3_12N> ObtenerPredio12(P1_B_3N predio) {
		List<P1_B_3_12N> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_B_3_12N where id_local=? and P1_B_3_NroPred=?",
						new String[] { predio.getId_local(),
								predio.getNro_Pred() + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_B_3_12N>();
			while (!cursor.isAfterLast()) {
				P1_B_3_12N obj = new P1_B_3_12N();
				obj.setId_local(predio.getId_local());
				obj.setP1_B_3_NroPred(predio.getNro_Pred());
				obj.setP1_B_3_12_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_B_3_12_Nro")));
				obj.setP1_B_3_12_NombComp(cursor.getString(cursor
						.getColumnIndex("P1_B_3_12_NombComp")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		}
		Cerrar();
		return lista;
	}

	public boolean GuardarPredio(P1_B_3N p1_b_3n, List<P1_B_3_12N> lista) {
		try {
			ContentValues contenido = new ContentValues();
			contenido.put("P1_B_3_InmCod", p1_b_3n.getP1_B_3_InmCod());
			contenido.put("P1_B_3_InmTip", p1_b_3n.getP1_B_3_InmTip());
			contenido.put("P1_B_3_1_Prop", p1_b_3n.getP1_B_3_1_Prop());
			contenido.put("P1_B_3_1_Prop_O", p1_b_3n.getP1_B_3_1_Prop_O());
			contenido.put("P1_B_3_2_AntReg_Cod",
					p1_b_3n.getP1_B_3_2_AntReg_Cod());
			contenido.put("P1_B_3_3_AntReg_Nro",
					p1_b_3n.getP1_B_3_3_AntReg_Nro());
			contenido.put("P1_B_3_4_Tipo_TProp",
					p1_b_3n.getP1_B_3_4_Tipo_TProp());
			contenido.put("P1_B_3_4_Tipo_TProp_O",
					p1_b_3n.getP1_B_3_4_Tipo_TProp_O());
			contenido.put("P1_B_3_5_FecTit", p1_b_3n.getP1_B_3_5_FecTit()
					.toString());
			contenido.put("P1_B_3_6_DocPos", p1_b_3n.getP1_B_3_6_DocPos());
			contenido.put("P1_B_3_6_DocPos_O", p1_b_3n.getP1_B_3_6_DocPos_O());
			contenido.put("P1_B_3_7_DocPos_Fech", p1_b_3n
					.getP1_B_3_7_DocPos_Fech().toString());
			contenido.put("P1_B_3_8_Tip_At_Pred",
					p1_b_3n.getP1_B_3_8_Tip_At_Pred());
			contenido.put("P1_B_3_8_At_Pred", p1_b_3n.getP1_B_3_8_At_Pred());
			contenido.put("P1_B_3_9_Tip_At_Local",
					p1_b_3n.getP1_B_3_9_Tip_At_Local());
			contenido.put("P1_B_3_9_At_Local", p1_b_3n.getP1_B_3_9_At_Local());
			contenido.put("P1_B_3_10_Comp", p1_b_3n.getP1_B_3_10_Comp());
			contenido.put("P1_B_3_11_CompCan", p1_b_3n.getP1_B_3_11_CompCan());
			contenido.put("P1_B_3_Obs", p1_b_3n.getP1_B_3_Obs());
			contenido.put("SwCompleto", p1_b_3n.getSwCompleto());
			contenido.put("Version", p1_b_3n.getVersion());
			if (ExistePredio(p1_b_3n)) {
				db = util.getWritableDatabase();
				db.update(
						"P1_B_3N",
						contenido,
						"id_local=? and Nro_Pred=?",
						new String[] { p1_b_3n.getId_local(),
								p1_b_3n.getNro_Pred() + "" });

				ContentValues c = new ContentValues();
				c.put("SwCompleto", p1_b_3n.getSwCompleto());
				db.update(
						"P1_B_2A_N",
						c,
						"id_local=? and Nro_Pred=?",
						new String[] { p1_b_3n.getId_local(),
								p1_b_3n.getNro_Pred() + "" });
			} else {
				db = util.getWritableDatabase();
				contenido.put("id_local", p1_b_3n.getId_local());
				contenido.put("Nro_Pred", p1_b_3n.getNro_Pred());
				db.insert("P1_B_3N", null, contenido);
				ContentValues c = new ContentValues();
				c.put("SwCompleto", p1_b_3n.getSwCompleto());
				db.update(
						"P1_B_2A_N",
						c,
						"id_local=? and Nro_Pred=?",
						new String[] { p1_b_3n.getId_local(),
								p1_b_3n.getNro_Pred() + "" });
			}
			db.close();

			if (lista != null) {
				for (int i = 0; i < p1_b_3n.getP1_B_3_11_CompCan(); i++) {
					ContentValues c = new ContentValues();
					c.put("P1_B_3_12_Nro", lista.get(i).getP1_B_3_12_Nro());
					c.put("P1_B_3_12_NombComp", lista.get(i)
							.getP1_B_3_12_NombComp());
					c.put("SwCompleto", lista.get(i).getSwCompleto());
					c.put("Version", lista.get(i).getVersion());
					if (!ExisteP1_B_3_12N(lista.get(i))) {
						db = util.getWritableDatabase();
						c.put("id_local", lista.get(i).getId_local());
						c.put("P1_B_3_NroPred", lista.get(i)
								.getP1_B_3_NroPred());
						db.insert("P1_B_3_12N", null, c);
						db.close();
					} else {
						db = util.getWritableDatabase();
						db.update(
								"P1_B_3_12N",
								c,
								"id_local=? and P1_B_3_NroPred=? and P1_B_3_12_Nro=?",
								new String[] { lista.get(i).getId_local(),
										lista.get(i).getP1_B_3_NroPred() + "",
										lista.get(i).getP1_B_3_12_Nro() + "" });
						db.close();
					}
				}
			}

		} catch (Exception e) {
			db.close();
			return false;
		}
		return true;
	}

	public boolean ExisteP1_B_3_12N(P1_B_3_12N obj) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"Select * from P1_B_3_12N where id_local=? and P1_B_3_NroPred=? and P1_B_3_12_Nro=?",
						new String[] { obj.getId_local(),
								obj.getP1_B_3_NroPred() + "",
								obj.getP1_B_3_12_Nro() + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public boolean ExistePredio(P1_B_3N p1_b_3n) {
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"Select * from P1_B_3N where id_local=? and Nro_Pred=?",
				new String[] { p1_b_3n.getId_local(),
						p1_b_3n.getNro_Pred() + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public List<P1_A_2N> ObtenerListadoIE(String id_local, int PC_F_1) {
		List<P1_A_2N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"Select * from P1_A_2N where id_local=? and PC_F_1=?",
				new String[] { id_local, PC_F_1 + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_A_2N>();
			while (!cursor.isAfterLast()) {
				P1_A_2N obj = new P1_A_2N();
				obj.setId_local(id_local);
				obj.setPC_F_1(PC_F_1);
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_1_NomIE(cursor.getString(cursor
						.getColumnIndex("P1_A_2_1_NomIE")));
				obj.setP1_A_2_2_Direc(cursor.getString(cursor
						.getColumnIndex("P1_A_2_2_Direc")));
				obj.setP1_A_2_3_DocTip(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_3_DocTip")));
				obj.setP1_A_2_3_DocNro(cursor.getString(cursor
						.getColumnIndex("P1_A_2_3_DocNro")));
				obj.setP1_A_2_4_TelfIE(cursor.getString(cursor
						.getColumnIndex("P1_A_2_4_TelfIE")));
				obj.setP1_A_2_4_TelfDir(cursor.getString(cursor
						.getColumnIndex("P1_A_2_4_TelfDir")));
				obj.setP1_A_2_5_EmailIE(cursor.getString(cursor
						.getColumnIndex("P1_A_2_5_EmailIE")));
				obj.setP1_A_2_5_EmailDir(cursor.getString(cursor
						.getColumnIndex("P1_A_2_5_EmailDir")));
				obj.setP1_A_2_6_Informant(cursor.getString(cursor
						.getColumnIndex("P1_A_2_6_Informant")));
				obj.setP1_A_2_7_InformantCarg(cursor.getString(cursor
						.getColumnIndex("P1_A_2_7_InformantCarg")));
				obj.setP1_A_2_8_Can_CMod_IE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_8_Can_CMod_IE")));
				obj.setP1_A_2_Obs(cursor.getString(cursor
						.getColumnIndex("P1_A_2_Obs")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		}
		Cerrar();
		return lista;
	}

	public P1_A_2N ObtenerIE(String id_local, int PC_F_1, int NroIE) {
		P1_A_2N obj = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"Select * from P1_A_2N where id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
						new String[] { id_local, PC_F_1 + "", NroIE + "" });
		if (cursor.moveToFirst()) {
			obj = new P1_A_2N();
			obj.setId_local(id_local);
			obj.setPC_F_1(PC_F_1);
			obj.setP1_A_2_NroIE(NroIE);
			obj.setP1_A_2_1_NomIE(cursor.getString(cursor
					.getColumnIndex("P1_A_2_1_NomIE")));
			obj.setP1_A_2_2_Direc(cursor.getString(cursor
					.getColumnIndex("P1_A_2_2_Direc")));
			obj.setP1_A_2_3_DocTip(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_3_DocTip")));
			obj.setP1_A_2_3_DocNro(cursor.getString(cursor
					.getColumnIndex("P1_A_2_3_DocNro")));
			obj.setP1_A_2_4_TelfIE(cursor.getString(cursor
					.getColumnIndex("P1_A_2_4_TelfIE")));
			obj.setP1_A_2_4_TelfDir(cursor.getString(cursor
					.getColumnIndex("P1_A_2_4_TelfDir")));
			obj.setP1_A_2_5_EmailIE(cursor.getString(cursor
					.getColumnIndex("P1_A_2_5_EmailIE")));
			obj.setP1_A_2_5_EmailDir(cursor.getString(cursor
					.getColumnIndex("P1_A_2_5_EmailDir")));
			obj.setP1_A_2_6_Informant(cursor.getString(cursor
					.getColumnIndex("P1_A_2_6_Informant")));
			obj.setP1_A_2_7_InformantCarg(cursor.getString(cursor
					.getColumnIndex("P1_A_2_7_InformantCarg")));
			obj.setP1_A_2_8_Can_CMod_IE(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_8_Can_CMod_IE")));
			obj.setP1_A_2_Obs(cursor.getString(cursor
					.getColumnIndex("P1_A_2_Obs")));
			obj.setSwCompleto(cursor.getInt(cursor.getColumnIndex("SwCompleto")));
			obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
		}
		Cerrar();
		return obj;
	}

	public boolean GuardarIE(P1_A_2N ie) {
		try {
			ContentValues contenido = new ContentValues();
			contenido.put("P1_A_2_1_NomIE", ie.getP1_A_2_1_NomIE());
			contenido.put("P1_A_2_2_Direc", ie.getP1_A_2_2_Direc());
			contenido.put("P1_A_2_3_DocTip", ie.getP1_A_2_3_DocTip());
			contenido.put("P1_A_2_3_DocNro", ie.getP1_A_2_3_DocNro());
			contenido.put("P1_A_2_4_TelfIE", ie.getP1_A_2_4_TelfIE());
			contenido.put("P1_A_2_4_TelfDir", ie.getP1_A_2_4_TelfDir());
			contenido.put("P1_A_2_5_EmailIE", ie.getP1_A_2_5_EmailIE());
			contenido.put("P1_A_2_5_EmailDir", ie.getP1_A_2_5_EmailDir());
			contenido.put("P1_A_2_6_Informant", ie.getP1_A_2_6_Informant());
			contenido.put("P1_A_2_7_InformantCarg",
					ie.getP1_A_2_7_InformantCarg());
			contenido.put("P1_A_2_8_Can_CMod_IE", ie.getP1_A_2_8_Can_CMod_IE());
			contenido.put("P1_A_2_Obs", ie.getP1_A_2_Obs());
			contenido.put("SwCompleto", ie.getSwCompleto());
			contenido.put("Version", ie.getVersion());

			db = util.getWritableDatabase();
			db.update(
					"P1_A_2N",
					contenido,
					"id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
					new String[] { ie.getId_local(), ie.getPC_F_1() + "",
							ie.getP1_A_2_NroIE() + "" });

			db.close();
			List<P1_A_2_8N> lista = ObtenerCodigosModulares(ie.getId_local(),
					ie.getPC_F_1(), ie.getP1_A_2_NroIE());
			if (lista == null) {
				for (int i = 0; i < ie.getP1_A_2_8_Can_CMod_IE(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("id_local", ie.getId_local());
					c.put("PC_F_1", ie.getPC_F_1());
					c.put("P1_A_2_NroIE", ie.getP1_A_2_NroIE());
					c.put("P1_A_2_9_NroCMod", i + 1);
					db.insert("P1_A_2_8N", null, c);
					db.close();

				}
			} else if (lista.size() < ie.getP1_A_2_8_Can_CMod_IE()) {
				for (int i = lista.size(); i < ie.getP1_A_2_8_Can_CMod_IE(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("id_local", ie.getId_local());
					c.put("PC_F_1", ie.getPC_F_1());
					c.put("P1_A_2_NroIE", ie.getP1_A_2_NroIE());
					c.put("P1_A_2_9_NroCMod", i + 1);
					db.insert("P1_A_2_8N", null, c);
					db.close();
				}
			} else if (lista.size() > ie.getP1_A_2_8_Can_CMod_IE()) {
				for (int i = ie.getP1_A_2_8_Can_CMod_IE(); i < lista.size(); i++) {
					db = util.getWritableDatabase();
					P1_A_2_8N Mod = lista.get(i);
					db.delete(
							"P1_C",
							"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
							new String[] { ie.getId_local(),
									ie.getPC_F_1() + "",
									ie.getP1_A_2_NroIE() + "",
									Mod.getP1_A_2_9_NroCMod() + "" });
					db.delete(
							"P1_A_2_9N",
							"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
							new String[] { ie.getId_local(),
									ie.getPC_F_1() + "",
									ie.getP1_A_2_NroIE() + "",
									Mod.getP1_A_2_9_NroCMod() + "" });
					db.delete(
							"P1_A_2_8N",
							"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
							new String[] { ie.getId_local(),
									ie.getPC_F_1() + "",
									ie.getP1_A_2_NroIE() + "", (i + 1) + "" });
					db.close();
				}
			}
		} catch (Exception e) {
			db.close();
			return false;
		}
		return true;
	}

	public boolean ExisteCodigoModular(P1_A_2_8N p1_a_2_8n) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"Select * from P1_A_2_8N where id_local=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
						new String[] { p1_a_2_8n.getId_local(),
								p1_a_2_8n.getP1_A_2_NroIE() + "",
								p1_a_2_8n.getP1_A_2_9_NroCMod() + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public void Cerrar() {
		cursor.close();
		db.close();
	}

	public List<P1_A_2_8N> ObtenerCodigosModulares(String id_local, int PC_F_1,
			int P1_A_2_NroIE) {
		List<P1_A_2_8N> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"Select * from P1_A_2_8N where id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
						new String[] { id_local, PC_F_1 + "", P1_A_2_NroIE + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_A_2_8N>();
			while (!cursor.isAfterLast()) {
				P1_A_2_8N obj = new P1_A_2_8N();
				obj.setId_local(id_local);
				obj.setPC_F_1(PC_F_1);
				obj.setP1_A_2_NroIE(P1_A_2_NroIE);
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9B_CodLocal(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9B_CodLocal")));
				obj.setP1_A_2_9C_Nivel(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9C_Nivel")));
				obj.setP1_A_2_9D_Car(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9D_Car")));
				obj.setP1_A_2_9E_NroAnex(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9E_NroAnex")));
				obj.setP1_A_2_9F_CantAnex(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9F_CantAnex")));
				obj.setP1_A_2_9G_T1_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9G_T1_Talu")));
				obj.setP1_A_2_9H_T1_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9H_T1_Taul")));
				obj.setP1_A_2_9I_T2_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9I_T2_Talu")));
				obj.setP1_A_2_9J_T2_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9J_T2_Taul")));
				obj.setP1_A_2_9K_T3_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9K_T3_Talu")));
				obj.setP1_A_2_9L_T3_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9L_T3_Taul")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		}
		Cerrar();
		return lista;
	}

	public P1_A_2_8N ObtenerCodModular(String id_local, int PC_F_1,
			int P1_A_2_NroIE, int NroCMod) {
		P1_A_2_8N obj = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"Select * from P1_A_2_8N where id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
						new String[] { id_local, PC_F_1 + "",
								P1_A_2_NroIE + "", NroCMod + "" });
		if (cursor.moveToFirst()) {
			obj = new P1_A_2_8N();
			obj.setId_local(id_local);
			obj.setPC_F_1(PC_F_1);
			obj.setP1_A_2_NroIE(P1_A_2_NroIE);
			obj.setP1_A_2_9_NroCMod(NroCMod);
			obj.setP1_A_2_9A_CMod(cursor.getString(cursor
					.getColumnIndex("P1_A_2_9A_CMod")));
			obj.setP1_A_2_9B_CodLocal(cursor.getString(cursor
					.getColumnIndex("P1_A_2_9B_CodLocal")));
			obj.setP1_A_2_9C_Nivel(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9C_Nivel")));
			obj.setP1_A_2_9D_Car(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9D_Car")));
			obj.setP1_A_2_9E_NroAnex(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9E_NroAnex")));
			obj.setP1_A_2_9F_CantAnex(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9F_CantAnex")));
			obj.setP1_A_2_9G_T1_Talu(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9G_T1_Talu")));
			obj.setP1_A_2_9H_T1_Taul(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9H_T1_Taul")));
			obj.setP1_A_2_9I_T2_Talu(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9I_T2_Talu")));
			obj.setP1_A_2_9J_T2_Taul(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9J_T2_Taul")));
			obj.setP1_A_2_9K_T3_Talu(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9K_T3_Talu")));
			obj.setP1_A_2_9L_T3_Taul(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9L_T3_Taul")));
			obj.setSwCompleto(cursor.getInt(cursor.getColumnIndex("SwCompleto")));
			obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
			cursor.moveToNext();
		}
		Cerrar();
		return obj;
	}

	public boolean GuardarCodModular(P1_A_2_8N obj) {
		try {
			ContentValues contenido = new ContentValues();
			contenido.put("P1_A_2_9A_CMod", obj.getP1_A_2_9A_CMod());
			contenido.put("P1_A_2_9B_CodLocal", obj.getP1_A_2_9B_CodLocal());
			contenido.put("P1_A_2_9C_Nivel", obj.getP1_A_2_9C_Nivel());
			contenido.put("P1_A_2_9D_Car", obj.getP1_A_2_9D_Car());
			contenido.put("P1_A_2_9E_NroAnex", obj.getP1_A_2_9E_NroAnex());
			contenido.put("P1_A_2_9F_CantAnex", obj.getP1_A_2_9F_CantAnex());
			contenido.put("P1_A_2_9G_T1_Talu", obj.getP1_A_2_9G_T1_Talu());
			contenido.put("P1_A_2_9H_T1_Taul", obj.getP1_A_2_9H_T1_Taul());
			contenido.put("P1_A_2_9I_T2_Talu", obj.getP1_A_2_9I_T2_Talu());
			contenido.put("P1_A_2_9J_T2_Taul", obj.getP1_A_2_9J_T2_Taul());
			contenido.put("P1_A_2_9K_T3_Talu", obj.getP1_A_2_9K_T3_Talu());
			contenido.put("P1_A_2_9L_T3_Taul", obj.getP1_A_2_9L_T3_Taul());
			contenido.put("SwCompleto", obj.getSwCompleto());
			contenido.put("Version", obj.getVersion());
			db = util.getWritableDatabase();
			db.update(
					"P1_A_2_8N",
					contenido,
					"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
					new String[] { obj.getId_local(), obj.getPC_F_1() + "",
							obj.getP1_A_2_NroIE() + "",
							obj.getP1_A_2_9_NroCMod() + "" });
			db.close();

			List<P1_A_2_9N> lista = ObtenerListadoAnexosA(obj.getId_local(),
					obj.getPC_F_1(), obj.getP1_A_2_NroIE(),
					obj.getP1_A_2_9_NroCMod());
			if (lista == null) {
				for (int i = 0; i < obj.getP1_A_2_9F_CantAnex(); i++) {
					ContentValues c = new ContentValues();
					c.put("id_local", obj.getId_local());
					c.put("PC_F_1", obj.getPC_F_1());
					c.put("P1_A_2_NroIE", obj.getP1_A_2_NroIE());
					c.put("P1_A_2_9_NroCMod", obj.getP1_A_2_9_NroCMod());
					c.put("P1_A_2_9A_CMod", obj.getP1_A_2_9A_CMod());
					c.put("P1_A_2_9_Nro", i + 1);
					db = util.getWritableDatabase();
					db.insert("P1_A_2_9N", null, c);
					db.close();
				}
			} else if (lista.size() < obj.getP1_A_2_9F_CantAnex()) {
				for (int i = lista.size(); i < obj.getP1_A_2_9F_CantAnex(); i++) {
					ContentValues c = new ContentValues();
					c.put("id_local", obj.getId_local());
					c.put("PC_F_1", obj.getPC_F_1());
					c.put("P1_A_2_NroIE", obj.getP1_A_2_NroIE());
					c.put("P1_A_2_9_NroCMod", obj.getP1_A_2_9_NroCMod());
					c.put("P1_A_2_9A_CMod", obj.getP1_A_2_9A_CMod());
					c.put("P1_A_2_9_Nro", i + 1);
					db = util.getWritableDatabase();
					db.insert("P1_A_2_9N", null, c);
					db.close();
				}
			} else if (lista.size() > obj.getP1_A_2_9F_CantAnex()) {
				for (int i = obj.getP1_A_2_9F_CantAnex(); i < lista.size(); i++) {
					P1_A_2_9N Anexo = lista.get(i);
					db = util.getWritableDatabase();
					db.delete(
							"P1_C",
							"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
							new String[] { obj.getId_local(),
									obj.getPC_F_1() + "",
									obj.getP1_A_2_NroIE() + "",
									obj.getP1_A_2_9_NroCMod() + "",
									Anexo.getP1_A_2_9_Nro() + "" });
					db.delete(
							"P1_A_2_9N",
							"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
							new String[] { obj.getId_local(),
									obj.getPC_F_1() + "",
									obj.getP1_A_2_NroIE() + "",
									obj.getP1_A_2_9_NroCMod() + "",
									Anexo.getP1_A_2_9_Nro() + "" });
				}
			}

			if (obj.getP1_A_2_9F_CantAnex() != 0) {
				for (int i = 0; i < obj.getP1_A_2_9F_CantAnex(); i++) {
					P1_A_2_9N an = new P1_A_2_9N();
					an.setId_local(obj.getId_local());
					an.setPC_F_1(obj.getPC_F_1());
					an.setP1_A_2_NroIE(obj.getP1_A_2_NroIE());
					an.setP1_A_2_9_NroCMod(obj.getP1_A_2_9_NroCMod());
					an.setP1_A_2_9A_CMod(obj.getP1_A_2_9A_CMod());
					an.setP1_A_2_9_Nro(i + 1);
					if (!ExisteAnexo(an)) {
						ContentValues c = new ContentValues();
						db = util.getWritableDatabase();
						c.put("id_local", an.getId_local());
						c.put("PC_F_1", an.getPC_F_1());
						c.put("P1_A_2_NroIE", an.getP1_A_2_NroIE());
						c.put("P1_A_2_9_NroCMod", an.getP1_A_2_9_NroCMod());
						c.put("P1_A_2_9A_CMod", an.getP1_A_2_9A_CMod());
						c.put("P1_A_2_9_Nro", an.getP1_A_2_9_Nro());
						db.insert("P1_A_2_9N", null, c);
						db.close();
					}
				}

				ContentValues c1 = new ContentValues();
				c1.put("P1_A_2_9A_CMod", obj.getP1_A_2_9A_CMod());
				Log.i("PC_1 PREDIO", "Predio " + obj.getPC_F_1());
				Log.i("PC_1 P1_A_2_NroIE",
						"P1_A_2_NroIE " + obj.getP1_A_2_NroIE());
				Log.i("PC_1 P1_A_2_9_NroCMod",
						"P1_A_2_9_NroCMod " + obj.getP1_A_2_9_NroCMod());
				db = util.getWritableDatabase();
				int i2 = db
						.update("P1_C",
								c1,
								"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
								new String[] { obj.getId_local(),
										obj.getPC_F_1() + "",
										obj.getP1_A_2_NroIE() + "",
										obj.getP1_A_2_9_NroCMod() + "" });
				Log.i("P1_C", "update 2 = " + i2);

				int i3 = db
						.update("P1_C_20N",
								c1,
								"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
								new String[] { obj.getId_local(),
										obj.getPC_F_1() + "",
										obj.getP1_A_2_NroIE() + "",
										obj.getP1_A_2_9_NroCMod() + "" });
				Log.i("P1_C_20N", "update 3 = " + i3);
				int i1 = db
						.update("P1_A_2_9N",
								c1,
								"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
								new String[] { obj.getId_local(),
										obj.getPC_F_1() + "",
										obj.getP1_A_2_NroIE() + "",
										obj.getP1_A_2_9_NroCMod() + "" });
				Log.i("P1_A_2_9N", "update 1 = " + i1);

				db.close();
			}
		} catch (Exception e) {
			db.close();
			return false;
		}
		return true;
	}

	public boolean ExisteAnexo(P1_A_2_9N obj) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"Select * from P1_A_2_9N where id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
						new String[] { obj.getId_local(), obj.getPC_F_1() + "",
								obj.getP1_A_2_NroIE() + "",
								obj.getP1_A_2_9_NroCMod() + "",
								obj.getP1_A_2_9_Nro() + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public List<P1_A_2_9N> ObtenerListadoAnexosA(String id_local, int PC_F_1,
			int P1_A_2_NroIE, int P1_A_2_9_NroCMod) {
		List<P1_A_2_9N> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"Select * from P1_A_2_9N where id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
						new String[] { id_local, PC_F_1 + "",
								P1_A_2_NroIE + "", P1_A_2_9_NroCMod + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_A_2_9N>();
			while (!cursor.isAfterLast()) {
				P1_A_2_9N obj = new P1_A_2_9N();
				obj.setId_local(id_local);
				obj.setPC_F_1(PC_F_1);
				obj.setP1_A_2_NroIE(P1_A_2_NroIE);
				obj.setP1_A_2_9_NroCMod(P1_A_2_9_NroCMod);
				obj.setP1_A_2_9_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_Nro")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_AnexNro")));
				obj.setP1_A_2_9_AnexNomb(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9_AnexNomb")));
				obj.setP1_A_2_9G_T1_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9G_T1_Talu")));
				obj.setP1_A_2_9H_T1_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9H_T1_Taul")));
				obj.setP1_A_2_9I_T2_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9I_T2_Talu")));
				obj.setP1_A_2_9J_T2_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9J_T2_Taul")));
				obj.setP1_A_2_9K_T3_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9K_T3_Talu")));
				obj.setP1_A_2_9L_T3_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9L_T3_Taul")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		}
		Cerrar();
		return lista;
	}

	public P1_A_2_9N ObtenerAnexoA(String id_local, int PC_F_1,
			int P1_A_2_NroIE, int P1_A_2_9_NroCMod, int P1_A_2_9_Nro) {
		P1_A_2_9N obj = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"Select * from P1_A_2_9N where id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
						new String[] { id_local, PC_F_1 + "",
								P1_A_2_NroIE + "", P1_A_2_9_NroCMod + "",
								P1_A_2_9_Nro + "" });
		if (cursor.moveToFirst()) {
			obj = new P1_A_2_9N();
			obj.setId_local(id_local);
			obj.setPC_F_1(PC_F_1);
			obj.setP1_A_2_NroIE(P1_A_2_NroIE);
			obj.setP1_A_2_9_NroCMod(P1_A_2_9_NroCMod);
			obj.setP1_A_2_9_Nro(P1_A_2_9_Nro);
			obj.setP1_A_2_9A_CMod(cursor.getString(cursor
					.getColumnIndex("P1_A_2_9A_CMod")));
			obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9_AnexNro")));
			obj.setP1_A_2_9_AnexNomb(cursor.getString(cursor
					.getColumnIndex("P1_A_2_9_AnexNomb")));
			obj.setP1_A_2_9G_T1_Talu(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9G_T1_Talu")));
			obj.setP1_A_2_9H_T1_Taul(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9H_T1_Taul")));
			obj.setP1_A_2_9I_T2_Talu(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9I_T2_Talu")));
			obj.setP1_A_2_9J_T2_Taul(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9J_T2_Taul")));
			obj.setP1_A_2_9K_T3_Talu(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9K_T3_Talu")));
			obj.setP1_A_2_9L_T3_Taul(cursor.getInt(cursor
					.getColumnIndex("P1_A_2_9L_T3_Taul")));
			obj.setSwCompleto(cursor.getInt(cursor.getColumnIndex("SwCompleto")));
			obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));

		}
		Cerrar();
		return obj;
	}

	public boolean ExisteAnexoNro(P1_A_2_9N obj, int nro) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_A_2_9N where id_local=? and PC_F_1=? and  P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro<>? and P1_A_2_9_AnexNro=?",
						new String[] { obj.getId_local(), obj.getPC_F_1() + "",
								obj.getP1_A_2_NroIE() + "",
								obj.getP1_A_2_9_NroCMod() + "",
								obj.getP1_A_2_9_Nro() + "", nro + "" });
		if (cursor.moveToFirst()) {
			return true;
		}
		return false;
	}

	public boolean GuardarAnexoA(P1_A_2_9N obj) {
		try {
			ContentValues contenido = new ContentValues();
			contenido.put("P1_A_2_9_AnexNro", obj.getP1_A_2_9_AnexNro());
			contenido.put("P1_A_2_9_AnexNomb", obj.getP1_A_2_9_AnexNomb());
			contenido.put("P1_A_2_9G_T1_Talu", obj.getP1_A_2_9G_T1_Talu());
			contenido.put("P1_A_2_9H_T1_Taul", obj.getP1_A_2_9H_T1_Taul());
			contenido.put("P1_A_2_9I_T2_Talu", obj.getP1_A_2_9I_T2_Talu());
			contenido.put("P1_A_2_9J_T2_Taul", obj.getP1_A_2_9J_T2_Taul());
			contenido.put("P1_A_2_9K_T3_Talu", obj.getP1_A_2_9K_T3_Talu());
			contenido.put("P1_A_2_9L_T3_Taul", obj.getP1_A_2_9L_T3_Taul());
			contenido.put("SwCompleto", obj.getSwCompleto());
			contenido.put("Version", obj.getVersion());
			db = util.getWritableDatabase();
			db.update(
					"P1_A_2_9N",
					contenido,
					"id_local=? and PC_F_1=? and  P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
					new String[] { obj.getId_local(), obj.getPC_F_1() + "",
							obj.getP1_A_2_NroIE() + "",
							obj.getP1_A_2_9_NroCMod() + "",
							obj.getP1_A_2_9_Nro() + "" });
			db.close();
			P1_C pc = new P1_C();
			pc.setId_local(obj.getId_local());
			pc.setPC_F_1(obj.getPC_F_1());
			pc.setP1_A_2_NroIE(obj.getP1_A_2_NroIE());
			pc.setP1_A_2_9_NroCMod(obj.getP1_A_2_9_NroCMod());
			pc.setP1_A_2_9_Nro(obj.getP1_A_2_9_Nro());
			pc.setP1_A_2_9A_CMod(obj.getP1_A_2_9A_CMod());
			pc.setP1_A_2_9_AnexNro(obj.getP1_A_2_9_AnexNro());
			if (!ExisteAnexoC(pc)) {
				ContentValues c = new ContentValues();
				c.put("id_local", pc.getId_local());
				c.put("PC_F_1", pc.getPC_F_1());
				c.put("P1_A_2_NroIE", pc.getP1_A_2_NroIE());
				c.put("P1_A_2_9_NroCMod", pc.getP1_A_2_9_NroCMod());
				c.put("P1_A_2_9_Nro", pc.getP1_A_2_9_Nro());
				c.put("P1_A_2_9A_CMod", pc.getP1_A_2_9A_CMod());
				c.put("P1_A_2_9_AnexNro", pc.getP1_A_2_9_AnexNro());
				db = util.getWritableDatabase();
				db.insert("P1_C", null, c);
				db.close();
			} else {
				ContentValues c = new ContentValues();
				c.put("P1_A_2_9A_CMod", pc.getP1_A_2_9A_CMod());
				c.put("P1_A_2_9_AnexNro", pc.getP1_A_2_9_AnexNro());
				db = util.getWritableDatabase();
				db.update(
						"P1_C",
						c,
						"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
						new String[] { pc.getId_local(), pc.getPC_F_1() + "",
								pc.getP1_A_2_NroIE() + "",
								pc.getP1_A_2_9_NroCMod() + "",
								pc.getP1_A_2_9_Nro() + "" });

				db.update(
						"P1_C_20N",
						c,
						"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
						new String[] { pc.getId_local(), pc.getPC_F_1() + "",
								pc.getP1_A_2_NroIE() + "",
								pc.getP1_A_2_9_NroCMod() + "",
								pc.getP1_A_2_9_Nro() + "" });
				db.close();
			}
		} catch (Exception e) {
			db.close();
			return false;
		}
		return true;
	}

	public void eliminarAnexo(P1_A_2_9N obj) {
		int total = 0;

		db = util.getWritableDatabase();
		db.delete(
				"P1_A_2_9N",
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "",
						obj.getP1_A_2_9_Nro() + "" });
		db.close();
		List<P1_A_2_9N> anexos = obtenerListadoAnexosPorCodigoModular(
				obj.getId_local(), obj.getPC_F_1(), obj.getP1_A_2_NroIE(),
				obj.getP1_A_2_9_NroCMod());

		db = util.getWritableDatabase();
		db.delete(
				"P1_C",
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "",
						obj.getP1_A_2_9_Nro() + "" });
		db.close();
		List<P1_C> listaAnexos = obtenerListadoAnexos(obj.getId_local(),
				obj.getPC_F_1(), obj.getP1_A_2_NroIE(),
				obj.getP1_A_2_9_NroCMod());

		db = util.getWritableDatabase();
		db.delete(
				"P1_C_20N",
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "",
						obj.getP1_A_2_9_Nro() + "" });
		db.close();
		List<P1_C_20N> servicios = obtenerListadoServicios(obj.getId_local(),
				obj.getPC_F_1(), obj.getP1_A_2_NroIE(),
				obj.getP1_A_2_9_NroCMod());

		if (anexos != null) {
			for (int i = obj.getP1_A_2_9_Nro(); i <= anexos.size(); i++) {
				db = util.getWritableDatabase();
				ContentValues a = new ContentValues();
				a.put("P1_A_2_9_Nro", i);
				db.update(
						"P1_A_2_9N",
						a,
						"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
						new String[] { obj.getId_local() + "",
								obj.getPC_F_1() + "",
								obj.getP1_A_2_NroIE() + "",
								obj.getP1_A_2_9_NroCMod() + "", (i + 1) + "" });
				db.close();
			}
		}

		if (listaAnexos != null) {
			for (int i = obj.getP1_A_2_9_Nro(); i <= listaAnexos.size(); i++) {
				db = util.getWritableDatabase();
				ContentValues b = new ContentValues();
				b.put("P1_A_2_9_Nro", i);
				db.update(
						"P1_C",
						b,
						"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
						new String[] { obj.getId_local() + "",
								obj.getPC_F_1() + "",
								obj.getP1_A_2_NroIE() + "",
								obj.getP1_A_2_9_NroCMod() + "", (i + 1) + "" });
				db.close();
			}
			if (servicios != null) {
				for (int i = obj.getP1_A_2_9_Nro(); i <= servicios.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("P1_A_2_9_Nro", i);
					db.update(
							"P1_C_20N",
							c,
							"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
							new String[] { obj.getId_local() + "",
									obj.getPC_F_1() + "",
									obj.getP1_A_2_NroIE() + "",
									obj.getP1_A_2_9_NroCMod() + "",
									(i + 1) + "" });
					db.close();
				}
			}
		}

		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_A_2_9N where id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
						new String[] { obj.getId_local() + "",
								obj.getPC_F_1() + "",
								obj.getP1_A_2_NroIE() + "",
								obj.getP1_A_2_9_NroCMod() + "" });
		if (cursor.moveToFirst()) {
			total = cursor.getCount();
		}
		db.close();
		db = util.getWritableDatabase();
		ContentValues c = new ContentValues();
		c.put("P1_A_2_9F_CantAnex", total);
		db.update(
				"P1_A_2_8N",
				c,
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "" });
		Cerrar();
	}

	public void eliminarAnexoSeccionC(P1_C obj) {
		int total = 0;

		db = util.getWritableDatabase();
		db.delete(
				"P1_A_2_9N",
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "",
						obj.getP1_A_2_9_Nro() + "" });
		db.close();
		List<P1_A_2_9N> anexos = obtenerListadoAnexosPorCodigoModular(
				obj.getId_local(), obj.getPC_F_1(), obj.getP1_A_2_NroIE(),
				obj.getP1_A_2_9_NroCMod());

		db = util.getWritableDatabase();
		db.delete(
				"P1_C",
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "",
						obj.getP1_A_2_9_Nro() + "" });
		db.close();
		List<P1_C> listaAnexos = obtenerListadoAnexos(obj.getId_local(),
				obj.getPC_F_1(), obj.getP1_A_2_NroIE(),
				obj.getP1_A_2_9_NroCMod());

		db = util.getWritableDatabase();
		db.delete(
				"P1_C_20N",
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "",
						obj.getP1_A_2_9_Nro() + "" });
		db.close();
		List<P1_C_20N> servicios = obtenerListadoServicios(obj.getId_local(),
				obj.getPC_F_1(), obj.getP1_A_2_NroIE(),
				obj.getP1_A_2_9_NroCMod());

		if (anexos != null) {
			for (int i = obj.getP1_A_2_9_Nro(); i <= anexos.size(); i++) {
				db = util.getWritableDatabase();
				ContentValues a = new ContentValues();
				a.put("P1_A_2_9_Nro", i);
				db.update(
						"P1_A_2_9N",
						a,
						"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
						new String[] { obj.getId_local() + "",
								obj.getPC_F_1() + "",
								obj.getP1_A_2_NroIE() + "",
								obj.getP1_A_2_9_NroCMod() + "", (i + 1) + "" });
				db.close();
			}
		}

		if (listaAnexos != null) {
			for (int i = obj.getP1_A_2_9_Nro(); i <= listaAnexos.size(); i++) {
				db = util.getWritableDatabase();
				ContentValues b = new ContentValues();
				b.put("P1_A_2_9_Nro", i);
				db.update(
						"P1_C",
						b,
						"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
						new String[] { obj.getId_local() + "",
								obj.getPC_F_1() + "",
								obj.getP1_A_2_NroIE() + "",
								obj.getP1_A_2_9_NroCMod() + "", (i + 1) + "" });
				db.close();
			}
			if (servicios != null) {
				for (int i = obj.getP1_A_2_9_Nro(); i <= servicios.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues c = new ContentValues();
					c.put("P1_A_2_9_Nro", i);
					db.update(
							"P1_C_20N",
							c,
							"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
							new String[] { obj.getId_local() + "",
									obj.getPC_F_1() + "",
									obj.getP1_A_2_NroIE() + "",
									obj.getP1_A_2_9_NroCMod() + "",
									(i + 1) + "" });
					db.close();
				}
			}
		}

		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_A_2_9N where id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
						new String[] { obj.getId_local() + "",
								obj.getPC_F_1() + "",
								obj.getP1_A_2_NroIE() + "",
								obj.getP1_A_2_9_NroCMod() + "" });
		if (cursor.moveToFirst()) {
			total = cursor.getCount();
		}
		db.close();
		db = util.getWritableDatabase();
		ContentValues c = new ContentValues();
		c.put("P1_A_2_9F_CantAnex", total);
		db.update(
				"P1_A_2_8N",
				c,
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "" });
		Cerrar();
	}

	public List<P1_A_2_9N> obtenerListadoAnexosPorCodigoModular(
			String id_local, int predio, int ie, int mod) {
		List<P1_A_2_9N> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_A_2_9N where id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
						new String[] { id_local + "", predio + "", ie + "",
								mod + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_A_2_9N>();
			while (!cursor.isAfterLast()) {
				P1_A_2_9N obj = new P1_A_2_9N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_Nro")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_AnexNro")));
				obj.setP1_A_2_9_AnexNomb(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9_AnexNomb")));
				obj.setP1_A_2_9G_T1_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9G_T1_Talu")));
				obj.setP1_A_2_9H_T1_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9H_T1_Taul")));
				obj.setP1_A_2_9I_T2_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9I_T2_Talu")));
				obj.setP1_A_2_9J_T2_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9J_T2_Taul")));
				obj.setP1_A_2_9K_T3_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9K_T3_Talu")));
				obj.setP1_A_2_9L_T3_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9L_T3_Taul")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P1_C> obtenerListadoAnexos(String id_local, int predio, int ie,
			int mod) {
		List<P1_C> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_C where id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
						new String[] { id_local + "", predio + "", ie + "",
								mod + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_C>();
			while (!cursor.isAfterLast()) {
				P1_C obj = new P1_C();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_Nro")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_AnexNro")));
				obj.setP1_C_1_CodLoc_Anex(cursor.getString(cursor
						.getColumnIndex("P1_C_1_CodLoc_Anex")));
				obj.setP1_C_2_ProvCod(cursor.getInt(cursor
						.getColumnIndex("P1_C_2_ProvCod")));
				obj.setP1_C_3_DistCod(cursor.getInt(cursor
						.getColumnIndex("P1_C_3_DistCod")));
				obj.setP1_C_4_CCPP(cursor.getString(cursor
						.getColumnIndex("P1_C_4_CCPP")));
				obj.setP1_C_5_NucleoUrb(cursor.getString(cursor
						.getColumnIndex("P1_C_5_NucleoUrb")));
				obj.setP1_C_6Dir_1_Tvia(cursor.getInt(cursor
						.getColumnIndex("P1_C_6Dir_1_Tvia")));
				obj.setP1_C_6Dir_2_Nomb(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_2_Nomb")));
				obj.setP1_C_6Dir_Nro(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_Nro")));
				obj.setP1_C_6Dir_4_Piso(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_4_Piso")));
				obj.setP1_C_6Dir_5_Mz(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_5_Mz")));
				obj.setP1_C_6Dir_6_Lt(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_6_Lt")));
				obj.setP1_C_6Dir_7_Sect(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_7_Sect")));
				obj.setP1_C_6Dir_8_Zona(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_8_Zona")));
				obj.setP1_C_6Dir_9_Et(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_9_Et")));
				obj.setP1_C_6Dir_10_Km(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_10_Km")));
				obj.setP1_C_7_RefDir(cursor.getString(cursor
						.getColumnIndex("P1_C_7_RefDir")));
				obj.setP1_C_8_InmCod(cursor.getString(cursor
						.getColumnIndex("P1_C_8_InmCod")));
				obj.setP1_C_8_InmTip(cursor.getInt(cursor
						.getColumnIndex("P1_C_8_InmTip")));
				obj.setP1_C_9_Prop(cursor.getInt(cursor
						.getColumnIndex("P1_C_9_Prop")));
				obj.setP1_C_9_Prop_O(cursor.getString(cursor
						.getColumnIndex("P1_C_9_Prop_O")));
				obj.setP1_C_10_AntReg_Cod(cursor.getInt(cursor
						.getColumnIndex("P1_C_10_AntReg_Cod")));
				obj.setP1_C_11_AntReg_Nro(cursor.getString(cursor
						.getColumnIndex("P1_C_11_AntReg_Nro")));
				obj.setP1_C_12_Tipo_TProp(cursor.getInt(cursor
						.getColumnIndex("P1_C_12_Tipo_TProp")));
				obj.setP1_C_12_Tipo_TProp_O(cursor.getString(cursor
						.getColumnIndex("P1_C_12_Tipo_TProp_O")));
				obj.setP1_C_13_FecTit(cursor.getString(cursor
						.getColumnIndex("P1_C_13_FecTit")));
				obj.setP1_C_14_DocPos(cursor.getInt(cursor
						.getColumnIndex("P1_C_14_DocPos")));
				obj.setP1_C_14_DocPos_O(cursor.getString(cursor
						.getColumnIndex("P1_C_14_DocPos_O")));
				obj.setP1_C_15_DocPos_Fech(cursor.getString(cursor
						.getColumnIndex("P1_C_15_DocPos_Fech")));
				obj.setP1_C_16_At_Pred(cursor.getFloat(cursor
						.getColumnIndex("P1_C_16_At_Pred")));
				obj.setP1_C_17_At_Local(cursor.getFloat(cursor
						.getColumnIndex("P1_C_17_At_Local")));
				obj.setP1_C_18_Comp(cursor.getInt(cursor
						.getColumnIndex("P1_C_18_Comp")));
				obj.setP1_C_19_CompCan(cursor.getInt(cursor
						.getColumnIndex("P1_C_19_CompCan")));
				obj.setP1_C_Obs(cursor.getString(cursor
						.getColumnIndex("P1_C_Obs")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P1_C_20N> obtenerListadoServicios(String id_local, int predio,
			int ie, int mod) {
		List<P1_C_20N> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_C_20N where id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
						new String[] { id_local + "", predio + "", ie + "",
								mod + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_C_20N>();
			while (!cursor.isAfterLast()) {
				P1_C_20N obj = new P1_C_20N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_Nro")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_AnexNro")));
				obj.setP1_C_20_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_C_20_Nro")));
				obj.setP1_C_20_NombComp(cursor.getString(cursor
						.getColumnIndex("P1_C_20_NombComp")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public void eliminarCodigosModulares(P1_A_2_8N obj) {
		int total = 0;

		db = util.getWritableDatabase();
		db.delete(
				"P1_A_2_8N",
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "" });
		db.close();
		List<P1_A_2_8N> modulares = obtenerListadoCodigosModularesPorIntitucion(
				obj.getId_local(), obj.getPC_F_1(), obj.getP1_A_2_NroIE());

		db = util.getWritableDatabase();
		db.delete(
				"P1_A_2_9N",
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "" });
		db.close();
		List<P1_A_2_9N> anexosXcod = obtenerListadoAnexosPorCodigoModular(
				obj.getId_local(), obj.getPC_F_1(), obj.getP1_A_2_NroIE());

		db = util.getWritableDatabase();
		db.delete(
				"P1_C",
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "" });
		db.close();
		List<P1_C> anexos = obtenerListadoAnexos(obj.getId_local(),
				obj.getPC_F_1(), obj.getP1_A_2_NroIE());

		db = util.getWritableDatabase();
		db.delete(
				"P1_C_20N",
				"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "",
						obj.getP1_A_2_9_NroCMod() + "" });
		db.close();
		List<P1_C_20N> servicios = obtenerListadoServicios(obj.getId_local(),
				obj.getPC_F_1(), obj.getP1_A_2_NroIE());

		if (modulares != null) {
			for (int i = obj.getP1_A_2_9_NroCMod(); i <= modulares.size(); i++) {
				db = util.getWritableDatabase();
				ContentValues a = new ContentValues();
				a.put("P1_A_2_9_NroCMod", i);
				db.update(
						"P1_A_2_8N",
						a,
						"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
						new String[] { obj.getId_local() + "",
								obj.getPC_F_1() + "",
								obj.getP1_A_2_NroIE() + "", (i + 1) + "" });
				db.close();
			}

			if (anexosXcod != null) {
				for (int i = obj.getP1_A_2_9_NroCMod(); i <= anexosXcod.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues a = new ContentValues();
					a.put("P1_A_2_9_NroCMod", i);
					db.update(
							"P1_A_2_9N",
							a,
							"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
							new String[] { obj.getId_local() + "",
									obj.getPC_F_1() + "",
									obj.getP1_A_2_NroIE() + "", (i + 1) + "" });
					db.close();
				}
			}

			if (anexos != null) {
				for (int i = obj.getP1_A_2_9_NroCMod(); i <= anexos.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues b = new ContentValues();
					b.put("P1_A_2_9_NroCMod", i);
					db.update(
							"P1_C",
							b,
							"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
							new String[] { obj.getId_local() + "",
									obj.getPC_F_1() + "",
									obj.getP1_A_2_NroIE() + "", (i + 1) + "" });
					db.close();
				}
				if (servicios != null) {
					for (int i = obj.getP1_A_2_9_NroCMod(); i <= servicios
							.size(); i++) {
						db = util.getWritableDatabase();
						ContentValues c = new ContentValues();
						c.put("P1_A_2_9_NroCMod", i);
						db.update(
								"P1_C_20N",
								c,
								"id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=?",
								new String[] { obj.getId_local() + "",
										obj.getPC_F_1() + "",
										obj.getP1_A_2_NroIE() + "",
										(i + 1) + "" });
						db.close();
					}
				}
			}
		}

		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_A_2_8N where id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
						new String[] { obj.getId_local() + "",
								obj.getPC_F_1() + "",
								obj.getP1_A_2_NroIE() + "" });
		if (cursor.moveToFirst()) {
			total = cursor.getCount();
		}
		db.close();
		db = util.getWritableDatabase();
		ContentValues c = new ContentValues();
		c.put("P1_A_2_8_Can_CMod_IE", total);
		db.update("P1_A_2N", c, "id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "" });
		Cerrar();
	}

	public List<P1_A_2_8N> obtenerListadoCodigosModularesPorIntitucion(
			String id_local, int predio, int ie) {
		List<P1_A_2_8N> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_A_2_8N where id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
						new String[] { id_local + "", predio + "", ie + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_A_2_8N>();
			while (!cursor.isAfterLast()) {
				P1_A_2_8N obj = new P1_A_2_8N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9B_CodLocal(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9B_CodLocal")));
				obj.setP1_A_2_9C_Nivel(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9C_Nivel")));
				obj.setP1_A_2_9D_Car(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9D_Car")));
				obj.setP1_A_2_9E_NroAnex(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9E_NroAnex")));
				obj.setP1_A_2_9F_CantAnex(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9F_CantAnex")));
				obj.setP1_A_2_9G_T1_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9G_T1_Talu")));
				obj.setP1_A_2_9H_T1_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9H_T1_Taul")));
				obj.setP1_A_2_9I_T2_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9I_T2_Talu")));
				obj.setP1_A_2_9J_T2_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9J_T2_Taul")));
				obj.setP1_A_2_9K_T3_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9K_T3_Talu")));
				obj.setP1_A_2_9L_T3_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9L_T3_Taul")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P1_A_2_9N> obtenerListadoAnexosPorCodigoModular(
			String id_local, int predio, int ie) {
		List<P1_A_2_9N> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_A_2_9N where id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
						new String[] { id_local + "", predio + "", ie + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_A_2_9N>();
			while (!cursor.isAfterLast()) {
				P1_A_2_9N obj = new P1_A_2_9N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_Nro")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_AnexNro")));
				obj.setP1_A_2_9_AnexNomb(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9_AnexNomb")));
				obj.setP1_A_2_9G_T1_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9G_T1_Talu")));
				obj.setP1_A_2_9H_T1_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9H_T1_Taul")));
				obj.setP1_A_2_9I_T2_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9I_T2_Talu")));
				obj.setP1_A_2_9J_T2_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9J_T2_Taul")));
				obj.setP1_A_2_9K_T3_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9K_T3_Talu")));
				obj.setP1_A_2_9L_T3_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9L_T3_Taul")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P1_C> obtenerListadoAnexos(String id_local, int predio, int ie) {
		List<P1_C> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_C where id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
						new String[] { id_local + "", predio + "", ie + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_C>();
			while (!cursor.isAfterLast()) {
				P1_C obj = new P1_C();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_Nro")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_AnexNro")));
				obj.setP1_C_1_CodLoc_Anex(cursor.getString(cursor
						.getColumnIndex("P1_C_1_CodLoc_Anex")));
				obj.setP1_C_2_ProvCod(cursor.getInt(cursor
						.getColumnIndex("P1_C_2_ProvCod")));
				obj.setP1_C_3_DistCod(cursor.getInt(cursor
						.getColumnIndex("P1_C_3_DistCod")));
				obj.setP1_C_4_CCPP(cursor.getString(cursor
						.getColumnIndex("P1_C_4_CCPP")));
				obj.setP1_C_5_NucleoUrb(cursor.getString(cursor
						.getColumnIndex("P1_C_5_NucleoUrb")));
				obj.setP1_C_6Dir_1_Tvia(cursor.getInt(cursor
						.getColumnIndex("P1_C_6Dir_1_Tvia")));
				obj.setP1_C_6Dir_2_Nomb(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_2_Nomb")));
				obj.setP1_C_6Dir_Nro(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_Nro")));
				obj.setP1_C_6Dir_4_Piso(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_4_Piso")));
				obj.setP1_C_6Dir_5_Mz(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_5_Mz")));
				obj.setP1_C_6Dir_6_Lt(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_6_Lt")));
				obj.setP1_C_6Dir_7_Sect(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_7_Sect")));
				obj.setP1_C_6Dir_8_Zona(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_8_Zona")));
				obj.setP1_C_6Dir_9_Et(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_9_Et")));
				obj.setP1_C_6Dir_10_Km(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_10_Km")));
				obj.setP1_C_7_RefDir(cursor.getString(cursor
						.getColumnIndex("P1_C_7_RefDir")));
				obj.setP1_C_8_InmCod(cursor.getString(cursor
						.getColumnIndex("P1_C_8_InmCod")));
				obj.setP1_C_8_InmTip(cursor.getInt(cursor
						.getColumnIndex("P1_C_8_InmTip")));
				obj.setP1_C_9_Prop(cursor.getInt(cursor
						.getColumnIndex("P1_C_9_Prop")));
				obj.setP1_C_9_Prop_O(cursor.getString(cursor
						.getColumnIndex("P1_C_9_Prop_O")));
				obj.setP1_C_10_AntReg_Cod(cursor.getInt(cursor
						.getColumnIndex("P1_C_10_AntReg_Cod")));
				obj.setP1_C_11_AntReg_Nro(cursor.getString(cursor
						.getColumnIndex("P1_C_11_AntReg_Nro")));
				obj.setP1_C_12_Tipo_TProp(cursor.getInt(cursor
						.getColumnIndex("P1_C_12_Tipo_TProp")));
				obj.setP1_C_12_Tipo_TProp_O(cursor.getString(cursor
						.getColumnIndex("P1_C_12_Tipo_TProp_O")));
				obj.setP1_C_13_FecTit(cursor.getString(cursor
						.getColumnIndex("P1_C_13_FecTit")));
				obj.setP1_C_14_DocPos(cursor.getInt(cursor
						.getColumnIndex("P1_C_14_DocPos")));
				obj.setP1_C_14_DocPos_O(cursor.getString(cursor
						.getColumnIndex("P1_C_14_DocPos_O")));
				obj.setP1_C_15_DocPos_Fech(cursor.getString(cursor
						.getColumnIndex("P1_C_15_DocPos_Fech")));
				obj.setP1_C_16_At_Pred(cursor.getFloat(cursor
						.getColumnIndex("P1_C_16_At_Pred")));
				obj.setP1_C_17_At_Local(cursor.getFloat(cursor
						.getColumnIndex("P1_C_17_At_Local")));
				obj.setP1_C_18_Comp(cursor.getInt(cursor
						.getColumnIndex("P1_C_18_Comp")));
				obj.setP1_C_19_CompCan(cursor.getInt(cursor
						.getColumnIndex("P1_C_19_CompCan")));
				obj.setP1_C_Obs(cursor.getString(cursor
						.getColumnIndex("P1_C_Obs")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P1_C_20N> obtenerListadoServicios(String id_local, int predio,
			int ie) {
		List<P1_C_20N> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_C_20N where id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
						new String[] { id_local + "", predio + "", ie + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_C_20N>();
			while (!cursor.isAfterLast()) {
				P1_C_20N obj = new P1_C_20N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_Nro")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_AnexNro")));
				obj.setP1_C_20_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_C_20_Nro")));
				obj.setP1_C_20_NombComp(cursor.getString(cursor
						.getColumnIndex("P1_C_20_NombComp")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public void eliminarInstitucion(P1_A_2N obj) {
		int total = 0;

		db = util.getWritableDatabase();
		db.delete("P1_A_2N", "id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "" });
		db.close();
		List<P1_A_2N> instituciones = obtenerListadoInstituciones(
				obj.getId_local(), obj.getPC_F_1());

		db = util.getWritableDatabase();
		db.delete("P1_A_2_8N", "id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "" });
		db.close();
		List<P1_A_2_8N> modulares = obtenerListadoCodigosModularesPorIntitucion(
				obj.getId_local(), obj.getPC_F_1());

		db = util.getWritableDatabase();
		db.delete("P1_A_2_9N", "id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "" });
		db.close();
		List<P1_A_2_9N> anexosXMod = obtenerListadoAnexosPorCodigoModular(
				obj.getId_local(), obj.getPC_F_1());

		db = util.getWritableDatabase();
		db.delete("P1_C", "id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "" });
		db.close();
		List<P1_C> anexos = obtenerListadoAnexos(obj.getId_local(),
				obj.getPC_F_1());

		db = util.getWritableDatabase();
		db.delete("P1_C_20N", "id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "",
						obj.getP1_A_2_NroIE() + "" });
		db.close();
		List<P1_C_20N> servicios = obtenerListadoServicios(obj.getId_local(),
				obj.getPC_F_1());

		Log.i("ELIMINAR", "11");
		if (instituciones != null) {
			Log.i("ELIMINAR", "12");
			for (int i = obj.getP1_A_2_NroIE(); i <= instituciones.size(); i++) {
				db = util.getWritableDatabase();
				ContentValues a = new ContentValues();
				a.put("P1_A_2_NroIE", i);
				db.update("P1_A_2N", a,
						"id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
						new String[] { obj.getId_local() + "",
								obj.getPC_F_1() + "", (i + 1) + "" });
				db.close();
			}
			Log.i("ELIMINAR", "13");
			if (modulares != null) {
				Log.i("ELIMINAR", "14");
				for (int i = obj.getP1_A_2_NroIE(); i <= modulares.size(); i++) {
					db = util.getWritableDatabase();
					ContentValues b = new ContentValues();
					b.put("P1_A_2_NroIE", i);
					db.update(
							"P1_A_2_8N",
							b,
							"id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
							new String[] { obj.getId_local() + "",
									obj.getPC_F_1() + "", (i + 1) + "" });
					db.close();
				}
				Log.i("ELIMINAR", "15");
				if (anexosXMod != null) {
					Log.i("ELIMINAR", "16");
					for (int i = obj.getP1_A_2_NroIE(); i <= anexosXMod.size(); i++) {
						db = util.getWritableDatabase();
						ContentValues c = new ContentValues();
						c.put("P1_A_2_NroIE", i);
						db.update(
								"P1_A_2_9N",
								c,
								"id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
								new String[] { obj.getId_local() + "",
										obj.getPC_F_1() + "", (i + 1) + "" });
						db.close();
					}
					Log.i("ELIMINAR", "17");
				}
				Log.i("ELIMINAR", "18");
				if (anexos != null) {
					Log.i("ELIMINAR", "19");
					for (int i = obj.getP1_A_2_NroIE(); i <= anexos.size(); i++) {
						db = util.getWritableDatabase();
						ContentValues d = new ContentValues();
						d.put("P1_A_2_NroIE", i);
						db.update(
								"P1_C",
								d,
								"id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
								new String[] { obj.getId_local() + "",
										obj.getPC_F_1() + "", (i + 1) + "" });
						db.close();
					}
					Log.i("ELIMINAR", "20");
					if (servicios != null) {
						Log.i("ELIMINAR", "21");
						for (int i = obj.getP1_A_2_NroIE(); i <= servicios
								.size(); i++) {
							db = util.getWritableDatabase();
							ContentValues e = new ContentValues();
							e.put("P1_A_2_NroIE", i);
							db.update(
									"P1_C_20N",
									e,
									"id_local=? and PC_F_1=? and P1_A_2_NroIE=?",
									new String[] { obj.getId_local() + "",
											obj.getPC_F_1() + "", (i + 1) + "" });
							db.close();
						}
						Log.i("ELIMINAR", "22");
					}
					Log.i("ELIMINAR", "23");
				}
				Log.i("ELIMINAR", "24");
			}
			Log.i("ELIMINAR", "25");
		}

		Log.i("ELIMINAR", "26");
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P1_A_2N where id_local=? and PC_F_1=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "" });
		if (cursor.moveToFirst()) {
			total = cursor.getCount();
		}
		db.close();
		Log.i("ELIMINAR", "27");
		db = util.getWritableDatabase();
		ContentValues f = new ContentValues();
		f.put("P1_A_1_Cant_IE", total);
		db.update("P1_A", f, "id_local=? and PC_F_1=?",
				new String[] { obj.getId_local() + "", obj.getPC_F_1() + "" });
		Cerrar();
		Log.i("ELIMINAR", "28");
	}

	public List<P1_A_2N> obtenerListadoInstituciones(String id_local, int predio) {
		List<P1_A_2N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P1_A_2N where id_local=? and PC_F_1=?",
				new String[] { id_local + "", predio + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_A_2N>();
			while (!cursor.isAfterLast()) {
				P1_A_2N obj = new P1_A_2N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_1_NomIE(cursor.getString(cursor
						.getColumnIndex("P1_A_2_1_NomIE")));
				obj.setP1_A_2_2_Direc(cursor.getString(cursor
						.getColumnIndex("P1_A_2_2_Direc")));
				obj.setP1_A_2_3_DocTip(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_3_DocTip")));
				obj.setP1_A_2_3_DocNro(cursor.getString(cursor
						.getColumnIndex("P1_A_2_3_DocNro")));
				obj.setP1_A_2_4_TelfIE(cursor.getString(cursor
						.getColumnIndex("P1_A_2_4_TelfIE")));
				obj.setP1_A_2_4_TelfDir(cursor.getString(cursor
						.getColumnIndex("P1_A_2_4_TelfDir")));
				obj.setP1_A_2_5_EmailIE(cursor.getString(cursor
						.getColumnIndex("P1_A_2_5_EmailIE")));
				obj.setP1_A_2_5_EmailDir(cursor.getString(cursor
						.getColumnIndex("P1_A_2_5_EmailDir")));
				obj.setP1_A_2_6_Informant(cursor.getString(cursor
						.getColumnIndex("P1_A_2_6_Informant")));
				obj.setP1_A_2_7_InformantCarg(cursor.getString(cursor
						.getColumnIndex("P1_A_2_7_InformantCarg")));
				obj.setP1_A_2_8_Can_CMod_IE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_8_Can_CMod_IE")));
				obj.setP1_A_2_Obs(cursor.getString(cursor
						.getColumnIndex("P1_A_2_Obs")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P1_A_2_8N> obtenerListadoCodigosModularesPorIntitucion(
			String id_local, int predio) {
		List<P1_A_2_8N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P1_A_2_8N where id_local=? and PC_F_1=?",
				new String[] { id_local + "", predio + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_A_2_8N>();
			while (!cursor.isAfterLast()) {
				P1_A_2_8N obj = new P1_A_2_8N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9B_CodLocal(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9B_CodLocal")));
				obj.setP1_A_2_9C_Nivel(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9C_Nivel")));
				obj.setP1_A_2_9D_Car(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9D_Car")));
				obj.setP1_A_2_9E_NroAnex(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9E_NroAnex")));
				obj.setP1_A_2_9F_CantAnex(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9F_CantAnex")));
				obj.setP1_A_2_9G_T1_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9G_T1_Talu")));
				obj.setP1_A_2_9H_T1_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9H_T1_Taul")));
				obj.setP1_A_2_9I_T2_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9I_T2_Talu")));
				obj.setP1_A_2_9J_T2_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9J_T2_Taul")));
				obj.setP1_A_2_9K_T3_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9K_T3_Talu")));
				obj.setP1_A_2_9L_T3_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9L_T3_Taul")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P1_A_2_9N> obtenerListadoAnexosPorCodigoModular(
			String id_local, int predio) {
		List<P1_A_2_9N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P1_A_2_9N where id_local=? and PC_F_1=?",
				new String[] { id_local + "", predio + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_A_2_9N>();
			while (!cursor.isAfterLast()) {
				P1_A_2_9N obj = new P1_A_2_9N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_Nro")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_AnexNro")));
				obj.setP1_A_2_9_AnexNomb(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9_AnexNomb")));
				obj.setP1_A_2_9G_T1_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9G_T1_Talu")));
				obj.setP1_A_2_9H_T1_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9H_T1_Taul")));
				obj.setP1_A_2_9I_T2_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9I_T2_Talu")));
				obj.setP1_A_2_9J_T2_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9J_T2_Taul")));
				obj.setP1_A_2_9K_T3_Talu(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9K_T3_Talu")));
				obj.setP1_A_2_9L_T3_Taul(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9L_T3_Taul")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P1_C> obtenerListadoAnexos(String id_local, int predio) {
		List<P1_C> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P1_C where id_local=? and PC_F_1=?",
				new String[] { id_local + "", predio + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_C>();
			while (!cursor.isAfterLast()) {
				P1_C obj = new P1_C();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_Nro")));
				obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_AnexNro")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_C_1_CodLoc_Anex(cursor.getString(cursor
						.getColumnIndex("P1_C_1_CodLoc_Anex")));
				obj.setP1_C_2_ProvCod(cursor.getInt(cursor
						.getColumnIndex("P1_C_2_ProvCod")));
				obj.setP1_C_3_DistCod(cursor.getInt(cursor
						.getColumnIndex("P1_C_3_DistCod")));
				obj.setP1_C_4_CCPP(cursor.getString(cursor
						.getColumnIndex("P1_C_4_CCPP")));
				obj.setP1_C_5_NucleoUrb(cursor.getString(cursor
						.getColumnIndex("P1_C_5_NucleoUrb")));
				obj.setP1_C_6Dir_1_Tvia(cursor.getInt(cursor
						.getColumnIndex("P1_C_6Dir_1_Tvia")));
				obj.setP1_C_6Dir_2_Nomb(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_2_Nomb")));
				obj.setP1_C_6Dir_Nro(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_Nro")));
				obj.setP1_C_6Dir_4_Piso(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_4_Piso")));
				obj.setP1_C_6Dir_5_Mz(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_5_Mz")));
				obj.setP1_C_6Dir_6_Lt(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_6_Lt")));
				obj.setP1_C_6Dir_7_Sect(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_7_Sect")));
				obj.setP1_C_6Dir_8_Zona(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_8_Zona")));
				obj.setP1_C_6Dir_9_Et(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_9_Et")));
				obj.setP1_C_6Dir_10_Km(cursor.getString(cursor
						.getColumnIndex("P1_C_6Dir_10_Km")));
				obj.setP1_C_7_RefDir(cursor.getString(cursor
						.getColumnIndex("P1_C_7_RefDir")));
				obj.setP1_C_8_InmCod(cursor.getString(cursor
						.getColumnIndex("P1_C_8_InmCod")));
				obj.setP1_C_8_InmTip(cursor.getInt(cursor
						.getColumnIndex("P1_C_8_InmTip")));
				obj.setP1_C_9_Prop(cursor.getInt(cursor
						.getColumnIndex("P1_C_9_Prop")));
				obj.setP1_C_9_Prop_O(cursor.getString(cursor
						.getColumnIndex("P1_C_9_Prop_O")));
				obj.setP1_C_10_AntReg_Cod(cursor.getInt(cursor
						.getColumnIndex("P1_C_10_AntReg_Cod")));
				obj.setP1_C_11_AntReg_Nro(cursor.getString(cursor
						.getColumnIndex("P1_C_11_AntReg_Nro")));
				obj.setP1_C_12_Tipo_TProp(cursor.getInt(cursor
						.getColumnIndex("P1_C_12_Tipo_TProp")));
				obj.setP1_C_12_Tipo_TProp_O(cursor.getString(cursor
						.getColumnIndex("P1_C_12_Tipo_TProp_O")));
				obj.setP1_C_13_FecTit(cursor.getString(cursor
						.getColumnIndex("P1_C_13_FecTit")));
				obj.setP1_C_14_DocPos(cursor.getInt(cursor
						.getColumnIndex("P1_C_14_DocPos")));
				obj.setP1_C_14_DocPos_O(cursor.getString(cursor
						.getColumnIndex("P1_C_14_DocPos_O")));
				obj.setP1_C_15_DocPos_Fech(cursor.getString(cursor
						.getColumnIndex("P1_C_15_DocPos_Fech")));
				obj.setP1_C_16_At_Pred(cursor.getFloat(cursor
						.getColumnIndex("P1_C_16_At_Pred")));
				obj.setP1_C_17_At_Local(cursor.getFloat(cursor
						.getColumnIndex("P1_C_17_At_Local")));
				obj.setP1_C_18_Comp(cursor.getInt(cursor
						.getColumnIndex("P1_C_18_Comp")));
				obj.setP1_C_19_CompCan(cursor.getInt(cursor
						.getColumnIndex("P1_C_19_CompCan")));
				obj.setP1_C_Obs(cursor.getString(cursor
						.getColumnIndex("P1_C_Obs")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public List<P1_C_20N> obtenerListadoServicios(String id_local, int predio) {
		List<P1_C_20N> lista = null;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P1_C_20N where id_local=? and PC_F_1=?",
				new String[] { id_local + "", predio + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_C_20N>();
			while (!cursor.isAfterLast()) {
				P1_C_20N obj = new P1_C_20N();
				obj.setId_local(cursor.getString(cursor
						.getColumnIndex("id_local")));
				obj.setPC_F_1(cursor.getInt(cursor.getColumnIndex("PC_F_1")));
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				obj.setP1_A_2_9_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_Nro")));
				obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_AnexNro")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_C_20_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_C_20_Nro")));
				obj.setP1_C_20_NombComp(cursor.getString(cursor
						.getColumnIndex("P1_C_20_NombComp")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setSwEnviado(cursor.getInt(cursor
						.getColumnIndex("SwEnviado")));
				obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(obj);
				cursor.moveToNext();
			}
		} else {
			Cerrar();
			return null;
		}
		Cerrar();
		return lista;
	}

	public boolean ExisteAnexoC(P1_C pc) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"Select * from P1_C where id_local=? and PC_F_1=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
						new String[] { pc.getId_local(), pc.getPC_F_1() + "",
								pc.getP1_A_2_NroIE() + "",
								pc.getP1_A_2_9_NroCMod() + "",
								pc.getP1_A_2_9_Nro() + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public int ContarAnexosC(String id_local, int PC_F_1) {
		int cant = 0;
		db = util.getReadableDatabase();
		cursor = db.rawQuery(
				"select * from P1_C where id_local=? and PC_F_1=?",
				new String[] { id_local, PC_F_1 + "" });
		if (cursor.moveToFirst()) {
			cant = cursor.getCount();
		}
		Cerrar();
		return cant;
	}

	public List<P1_C> ObtenerListadoAnexosC(String id_local, int PC_F_1) {
		List<P1_C> lista = null;
		db = util.getReadableDatabase();
		Log.i("PREDIO", "" + PC_F_1);
		cursor = db.rawQuery(
				"Select * from P1_C where id_local=? and PC_F_1=?",
				new String[] { id_local, PC_F_1 + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_C>();
			while (!cursor.isAfterLast()) {
				P1_C obj = new P1_C();
				obj.setId_local(id_local);
				obj.setPC_F_1(PC_F_1);
				obj.setP1_A_2_NroIE(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_NroIE")));
				obj.setP1_A_2_9A_CMod(cursor.getString(cursor
						.getColumnIndex("P1_A_2_9A_CMod")));
				obj.setP1_A_2_9_AnexNro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_AnexNro")));
				obj.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				obj.setP1_A_2_9_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_Nro")));
				obj.setP1_A_2_9_NroCMod(cursor.getInt(cursor
						.getColumnIndex("P1_A_2_9_NroCMod")));
				lista.add(obj);
				cursor.moveToNext();
			}
		}
		Cerrar();
		return lista;
	}

	public P1_C ObtenerAnexoC(P1_C obj) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_C where id_local=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
						new String[] { obj.getId_local(),
								obj.getP1_A_2_NroIE() + "",
								obj.getP1_A_2_9_NroCMod() + "",
								obj.getP1_A_2_9_Nro() + "" });
		if (cursor.moveToFirst()) {
			obj.setP1_C_1_CodLoc_Anex(cursor.getString(cursor
					.getColumnIndex("P1_C_1_CodLoc_Anex")));
			obj.setP1_C_2_ProvCod(cursor.getInt(cursor
					.getColumnIndex("P1_C_2_ProvCod")));
			obj.setP1_C_3_DistCod(cursor.getInt(cursor
					.getColumnIndex("P1_C_3_DistCod")));
			obj.setP1_C_4_CCPP(cursor.getString(cursor
					.getColumnIndex("P1_C_4_CCPP")));
			obj.setP1_C_5_NucleoUrb(cursor.getString(cursor
					.getColumnIndex("P1_C_5_NucleoUrb")));
			obj.setP1_C_6Dir_1_Tvia(cursor.getInt(cursor
					.getColumnIndex("P1_C_6Dir_1_Tvia")));
			obj.setP1_C_6Dir_2_Nomb(cursor.getString(cursor
					.getColumnIndex("P1_C_6Dir_2_Nomb")));
			obj.setP1_C_6Dir_Nro(cursor.getString(cursor
					.getColumnIndex("P1_C_6Dir_Nro")));
			obj.setP1_C_6Dir_4_Piso(cursor.getString(cursor
					.getColumnIndex("P1_C_6Dir_4_Piso")));
			obj.setP1_C_6Dir_5_Mz(cursor.getString(cursor
					.getColumnIndex("P1_C_6Dir_5_Mz")));
			obj.setP1_C_6Dir_6_Lt(cursor.getString(cursor
					.getColumnIndex("P1_C_6Dir_6_Lt")));
			obj.setP1_C_6Dir_7_Sect(cursor.getString(cursor
					.getColumnIndex("P1_C_6Dir_7_Sect")));
			obj.setP1_C_6Dir_8_Zona(cursor.getString(cursor
					.getColumnIndex("P1_C_6Dir_8_Zona")));
			obj.setP1_C_6Dir_9_Et(cursor.getString(cursor
					.getColumnIndex("P1_C_6Dir_9_Et")));
			obj.setP1_C_6Dir_10_Km(cursor.getString(cursor
					.getColumnIndex("P1_C_6Dir_10_Km")));
			obj.setP1_C_7_RefDir(cursor.getString(cursor
					.getColumnIndex("P1_C_7_RefDir")));
			obj.setP1_C_8_InmCod(cursor.getString(cursor
					.getColumnIndex("P1_C_8_InmCod")));
			obj.setP1_C_8_InmTip(cursor.getInt(cursor
					.getColumnIndex("P1_C_8_InmTip")));
			obj.setP1_C_9_Prop(cursor.getInt(cursor
					.getColumnIndex("P1_C_9_Prop")));
			obj.setP1_C_9_Prop_O(cursor.getString(cursor
					.getColumnIndex("P1_C_9_Prop_O")));
			obj.setP1_C_10_AntReg_Cod(cursor.getInt(cursor
					.getColumnIndex("P1_C_10_AntReg_Cod")));
			obj.setP1_C_11_AntReg_Nro(cursor.getString(cursor
					.getColumnIndex("P1_C_11_AntReg_Nro")));
			obj.setP1_C_12_Tipo_TProp(cursor.getInt(cursor
					.getColumnIndex("P1_C_12_Tipo_TProp")));
			obj.setP1_C_12_Tipo_TProp_O(cursor.getString(cursor
					.getColumnIndex("P1_C_12_Tipo_TProp_O")));
			obj.setP1_C_13_FecTit(cursor.getString(cursor
					.getColumnIndex("P1_C_13_FecTit")));
			obj.setP1_C_14_DocPos(cursor.getInt(cursor
					.getColumnIndex("P1_C_14_DocPos")));
			obj.setP1_C_14_DocPos_O(cursor.getString(cursor
					.getColumnIndex("P1_C_14_DocPos_O")));
			obj.setP1_C_15_DocPos_Fech(cursor.getString(cursor
					.getColumnIndex("P1_C_15_DocPos_Fech")));
			obj.setP1_C_16_Tip_At_Pred(cursor.getInt(cursor
					.getColumnIndex("P1_C_16_Tip_At_Pred")));
			obj.setP1_C_16_At_Pred(cursor.getFloat(cursor
					.getColumnIndex("P1_C_16_At_Pred")));
			obj.setP1_C_17_Tip_At_Local(cursor.getInt(cursor
					.getColumnIndex("P1_C_17_Tip_At_Local")));
			obj.setP1_C_17_At_Local(cursor.getFloat(cursor
					.getColumnIndex("P1_C_17_At_Local")));
			obj.setP1_C_18_Comp(cursor.getInt(cursor
					.getColumnIndex("P1_C_18_Comp")));
			obj.setP1_C_19_CompCan(cursor.getInt(cursor
					.getColumnIndex("P1_C_19_CompCan")));
			obj.setP1_C_Obs(cursor.getString(cursor.getColumnIndex("P1_C_Obs")));
			obj.setSwCompleto(cursor.getInt(cursor.getColumnIndex("SwCompleto")));
			obj.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
		}
		Cerrar();
		return obj;
	}

	public List<P1_C_20N> ObtenerAnexoC20(P1_C obj) {
		List<P1_C_20N> lista = null;
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"select * from P1_C_20N where id_local=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
						new String[] { obj.getId_local(),
								obj.getP1_A_2_NroIE() + "",
								obj.getP1_A_2_9_NroCMod() + "",
								obj.getP1_A_2_9_Nro() + "" });
		if (cursor.moveToFirst()) {
			lista = new ArrayList<P1_C_20N>();
			while (!cursor.isAfterLast()) {
				P1_C_20N p = new P1_C_20N();
				p.setId_local(obj.getId_local());
				p.setP1_A_2_NroIE(obj.getP1_A_2_NroIE());
				p.setP1_A_2_9_NroCMod(obj.getP1_A_2_9_NroCMod());
				p.setP1_A_2_9_Nro(obj.getP1_A_2_9_Nro());
				p.setP1_A_2_9A_CMod(obj.getP1_A_2_9A_CMod());
				p.setP1_A_2_9_AnexNro(obj.getP1_A_2_9_AnexNro());
				p.setP1_C_20_Nro(cursor.getInt(cursor
						.getColumnIndex("P1_C_20_Nro")));
				p.setP1_C_20_NombComp(cursor.getString(cursor
						.getColumnIndex("P1_C_20_NombComp")));
				p.setSwCompleto(cursor.getInt(cursor
						.getColumnIndex("SwCompleto")));
				p.setVersion(cursor.getInt(cursor.getColumnIndex("Version")));
				lista.add(p);
				cursor.moveToNext();
			}
		}
		Cerrar();
		return lista;
	}

	public boolean GuardarAnexoC(P1_C obj, List<P1_C_20N> p) {

		try {
			ContentValues contenido = new ContentValues();
			contenido.put("P1_C_1_CodLoc_Anex", obj.getP1_C_1_CodLoc_Anex());
			contenido.put("P1_C_2_ProvCod", obj.getP1_C_2_ProvCod());
			contenido.put("P1_C_3_DistCod", obj.getP1_C_3_DistCod());
			contenido.put("P1_C_4_CCPP", obj.getP1_C_4_CCPP());
			contenido.put("P1_C_5_NucleoUrb", obj.getP1_C_5_NucleoUrb());
			contenido.put("P1_C_6Dir_1_Tvia", obj.getP1_C_6Dir_1_Tvia());
			contenido.put("P1_C_6Dir_2_Nomb", obj.getP1_C_6Dir_2_Nomb());
			contenido.put("P1_C_6Dir_Nro", obj.getP1_C_6Dir_Nro());
			contenido.put("P1_C_6Dir_4_Piso", obj.getP1_C_6Dir_4_Piso());
			contenido.put("P1_C_6Dir_5_Mz", obj.getP1_C_6Dir_5_Mz());
			contenido.put("P1_C_6Dir_6_Lt", obj.getP1_C_6Dir_6_Lt());
			contenido.put("P1_C_6Dir_7_Sect", obj.getP1_C_6Dir_7_Sect());
			contenido.put("P1_C_6Dir_8_Zona", obj.getP1_C_6Dir_8_Zona());
			contenido.put("P1_C_6Dir_9_Et", obj.getP1_C_6Dir_9_Et());
			contenido.put("P1_C_6Dir_10_Km", obj.getP1_C_6Dir_10_Km());
			contenido.put("P1_C_7_RefDir", obj.getP1_C_7_RefDir());
			contenido.put("P1_C_8_InmCod", obj.getP1_C_8_InmCod());
			contenido.put("P1_C_8_InmTip", obj.getP1_C_8_InmTip());
			contenido.put("P1_C_9_Prop", obj.getP1_C_9_Prop());
			contenido.put("P1_C_9_Prop_O", obj.getP1_C_9_Prop_O());
			contenido.put("P1_C_10_AntReg_Cod", obj.getP1_C_10_AntReg_Cod());
			contenido.put("P1_C_11_AntReg_Nro", obj.getP1_C_11_AntReg_Nro());
			contenido.put("P1_C_12_Tipo_TProp", obj.getP1_C_12_Tipo_TProp());
			contenido
					.put("P1_C_12_Tipo_TProp_O", obj.getP1_C_12_Tipo_TProp_O());
			contenido.put("P1_C_13_FecTit", obj.getP1_C_13_FecTit());
			contenido.put("P1_C_14_DocPos", obj.getP1_C_14_DocPos());
			contenido.put("P1_C_14_DocPos_O", obj.getP1_C_14_DocPos_O());
			contenido.put("P1_C_15_DocPos_Fech", obj.getP1_C_15_DocPos_Fech());
			contenido.put("P1_C_16_Tip_At_Pred", obj.getP1_C_16_Tip_At_Pred());
			contenido.put("P1_C_16_At_Pred", obj.getP1_C_16_At_Pred());
			contenido
					.put("P1_C_17_Tip_At_Local", obj.getP1_C_17_Tip_At_Local());
			contenido.put("P1_C_17_At_Local", obj.getP1_C_17_At_Local());
			contenido.put("P1_C_18_Comp", obj.getP1_C_18_Comp());
			contenido.put("P1_C_19_CompCan", obj.getP1_C_19_CompCan());
			contenido.put("P1_C_Obs", obj.getP1_C_Obs());
			contenido.put("Version", obj.getVersion());
			contenido.put("SwCompleto", obj.getSwCompleto());
			db = util.getWritableDatabase();
			db.update(
					"P1_C",
					contenido,
					"id_local=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=?",
					new String[] { obj.getId_local(),
							obj.getP1_A_2_NroIE() + "",
							obj.getP1_A_2_9_NroCMod() + "",
							obj.getP1_A_2_9_Nro() + "" });
			db.close();
			if (p != null) {
				for (int i = 0; i < obj.getP1_C_19_CompCan(); i++) {
					ContentValues c = new ContentValues();
					c.put("P1_C_20_NombComp", p.get(i).getP1_C_20_NombComp());
					c.put("SwCompleto", p.get(i).getSwCompleto());
					c.put("Version", p.get(i).getVersion());
					if (!ExisteP1_C_20N(p.get(i))) {
						db = util.getWritableDatabase();
						c.put("id_local", p.get(i).getId_local());
						c.put("P1_A_2_9_NroCMod", p.get(i)
								.getP1_A_2_9_NroCMod());
						c.put("P1_A_2_9_Nro", p.get(i).getP1_A_2_9_Nro());
						c.put("P1_A_2_NroIE", p.get(i).getP1_A_2_NroIE());
						c.put("P1_A_2_9A_CMod", p.get(i).getP1_A_2_9A_CMod());
						c.put("P1_A_2_9_AnexNro", p.get(i)
								.getP1_A_2_9_AnexNro());
						c.put("P1_C_20_Nro", i + 1);
						db.insert("P1_C_20N", null, c);
						db.close();
					} else {
						db = util.getWritableDatabase();
						db.update(
								"P1_C_20N",
								c,
								"id_local=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=? and P1_C_20_Nro=?",
								new String[] { p.get(i).getId_local(),
										p.get(i).getP1_A_2_NroIE() + "",
										p.get(i).getP1_A_2_9_NroCMod() + "",
										p.get(i).getP1_A_2_9_Nro() + "",
										p.get(i).getP1_C_20_Nro() + "" });
						db.close();
					}
				}
			}
		} catch (Exception e) {
			db.close();
			return false;
		}
		return true;
	}

	public boolean ExisteP1_C_20N(P1_C_20N p) {
		db = util.getReadableDatabase();
		cursor = db
				.rawQuery(
						"Select * from P1_C_20N where id_local=? and P1_A_2_NroIE=? and P1_A_2_9_NroCMod=? and P1_A_2_9_Nro=? and P1_C_20_Nro=?",
						new String[] { p.getId_local(),
								p.getP1_A_2_NroIE() + "",
								p.getP1_A_2_9_NroCMod() + "",
								p.getP1_A_2_9_Nro() + "",
								p.getP1_C_20_Nro() + "" });
		if (cursor.moveToFirst()) {
			Cerrar();
			return true;
		} else {
			Cerrar();
			return false;
		}
	}

	public boolean EliminarPredio(String id_local, int Nro_Pred) {
		// try {
		String[] args = new String[] { id_local, Nro_Pred + "" };
		String[] arg = new String[] { id_local };
		P1_B p1_b = ObtenerSeccionB(id_local);
		int total = p1_b.getP1_B_1_TPred();
		if (total == 2 && Nro_Pred == 2) {
			if (Nro_Pred != 1) {
				db = util.getWritableDatabase();
				db.delete("PCar", "id_local=? and PC_F_1=?", args);
				db.delete("PCar_C_1N", "id_local=? and PC_F_1=?", args);
				db.close();
			}
			db = util.getWritableDatabase();
			ContentValues c = new ContentValues();
			c.put("P1_B_1_TPred", p1_b.getP1_B_1_TPred() - 1);
			c.put("P1_B_2_PredCol", 0);
			db.update("P1_B", c, "id_local=?", arg);
			db.delete("P1_B_2A_N", "id_local=? and Nro_Pred=?", args);
			db.delete("P1_B_3N", "id_local=? and Nro_Pred=?", args);
			db.delete("P1_B_3_12N", "id_local=? and P1_B_3_NroPred=?", args);

			db.delete("P2_A", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_B", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_B_9N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_B_10N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_B_11N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_B_12N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });

			db.delete("P2_C", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D_1N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D_5N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D_3N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D_7N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D_9N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });

			db.delete("P2_E", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });

			db.delete("P2_F", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.close();
		} else if (total > 2) {
			List<P1_B_2A_N> lSecB_2N = ObtenerSeccionB_2N(id_local);
			int cantNC = 0;
			for (P1_B_2A_N obj : lSecB_2N) {
				if (obj.getP1_B_2A_PredNoCol() == 1) {
					cantNC++;
				}
			}
			P1_B_2A_N secb_2n = lSecB_2N.get(Nro_Pred - 1);

			AbrirEscritura();
			ContentValues c = new ContentValues();
			c.put("P1_B_1_TPred", p1_b.getP1_B_1_TPred() - 1);
			if (secb_2n.getP1_B_2A_PredNoCol() == 0) {
				// es colindante
				if (p1_b.getP1_B_1_TPred() == 2) {
					c.put("P1_B_2_PredCol", 0);
				}
				db.update("P1_B", c, "id_local=?", arg);
			} else if (secb_2n.getP1_B_2A_PredNoCol() == 1) {
				// es no colindante
				if (cantNC == 1) {
					c.put("P1_B_2_PredCol", 1);
					db.update("P1_B", c, "id_local=?", arg);
				} else {
					db.update("P1_B", c, "id_local=?", arg);
				}

			}

			db.delete("P1_B_2A_N", "id_local=? and Nro_Pred=?", args);
			db.delete("P1_B_3N", "id_local=? and Nro_Pred=?", args);
			db.delete("P1_B_3_12N", "id_local=? and P1_B_3_NroPred=?", args);
			CerrarDB();

			for (int i = Nro_Pred; i < total; i++) {
				db = util.getWritableDatabase();
				ContentValues c1 = new ContentValues();
				c1.put("Nro_Pred", i);
				db.update("P1_B_2A_N", c1, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (i + 1) + "" });
				db.update("P1_B_3N", c1, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (i + 1) + "" });
				c1 = new ContentValues();
				c1.put("P1_B_3_NroPred", i);
				db.update("P1_B_3_12N", c1, "id_local=? and P1_B_3_NroPred=?",
						new String[] { id_local, (i + 1) + "" });
				db.close();
			}

			// Eliminar lo que se necesita eliminar

			db = util.getWritableDatabase();
			db.delete("PCar", "id_local=? and PC_F_1=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("PCar_C_1N", "id_local=? and PC_F_1=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_A", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_B", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_B_9N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_B_10N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_B_11N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_B_12N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_C", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D_1N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D_5N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D_3N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D_7N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_D_9N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_E", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_F", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_G", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P2_G_2N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("PUNTO3", "codigoLocalPadron=? and codigoPredio=?",
					new String[] { id_local, Nro_Pred + "" });
			db.delete("PUNTOS_GPS", "codigoLocalPadron=? and codigoPredio=?",
					new String[] { id_local, Nro_Pred + "" });
			db.delete("FRENTE_LINDEROS", "id_local=? and P4_NroPred=?",
					new String[] { id_local, Nro_Pred + "" });
			db.delete("P4_2N", "id_local=? and P4_NroPred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P5", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P5_N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P5_F", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P6_1", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P6_1_8N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P6_1_10N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P6_2", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P6_2_4N", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P7", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P8", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });
			db.delete("P9_F", "id_local=? and Nro_Pred=?", new String[] {
					id_local, Nro_Pred + "" });

			for (int pred = Nro_Pred; pred < total; pred++) {
				c = new ContentValues();
				c.put("PC_F_1", pred);
				// Tabla PCar
				db.update("PCar", c, "id_local=? and PC_F_1=?", new String[] {
						id_local, (pred + 1) + "" });
				db.update("PCar_C_1N", c, "id_local=? and PC_F_1=?",
						new String[] { id_local, (pred + 1) + "" });

				c = new ContentValues();
				c.put("Nro_Pred", pred);

				// Tabla P2_A
				db.update("P2_A", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });

				// Tabla P2_B
				db.update("P2_B", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });
				db.update("P2_B_9N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });
				db.update("P2_B_10N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });
				db.update("P2_B_11N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });
				db.update("P2_B_12N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });

				// Tabla P2_C
				db.update("P2_C", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });

				// Tabla P2_D
				db.update("P2_D", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });
				db.update("P2_D_1N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });
				db.update("P2_D_5N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });
				db.update("P2_D_3N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });
				db.update("P2_D_7N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });
				db.update("P2_D_9N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });

				// Tabla P2_E
				db.update("P2_E", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });

				// Tabla P2_F
				db.update("P2_F", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });

				// Tabla P2_G
				db.update("P2_G", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });
				db.update("P2_G_2N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });

				c = new ContentValues();
				c.put("codigoPredio", pred);

				// Tabla PUNTO3
				db.update("PUNTO3", c,
						"codigoLocalPadron=? and codigoPredio=?", new String[] {
								id_local, (pred + 1) + "" });
				db.update("PUNTOS_GPS", c,
						"codigoLocalPadron=? and codigoPredio=?", new String[] {
								id_local, (pred + 1) + "" });

				c = new ContentValues();
				c.put("P4_NroPred", pred);

				// Tabla FRENTE_LINDEROS
				db.update("FRENTE_LINDEROS", c, "id_local=? and P4_NroPred=?",
						new String[] { id_local, (pred + 1) + "" });
				db.update("P4_2N", c, "id_local=? and P4_NroPred=?",
						new String[] { id_local, (pred + 1) + "" });

				c = new ContentValues();
				c.put("Nro_Pred", pred);

				// Tabla P5
				db.update("P5", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });
				db.update("P5_N", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });
				db.update("P5_F", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });

				// Tabla P6_1
				db.update("P6_1", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });
				db.update("P6_1_8N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });
				db.update("P6_1_10N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });
				db.update("P6_2", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });
				db.update("P6_2_4N", c, "id_local=? and Nro_Pred=?",
						new String[] { id_local, (pred + 1) + "" });

				// Tablas P7
				db.update("P7", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });

				// Tablas P8
				db.update("P8", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });

				// Tablas P9
				db.update("P9_F", c, "id_local=? and Nro_Pred=?", new String[] {
						id_local, (pred + 1) + "" });

			}
		}
		db.close();
		return true;
		// } catch (Exception e) {
		// db.close();
		// return false;
		// }

	}

	public void AbrirLectura() {
		db = util.getReadableDatabase();
	}

	public void AbrirEscritura() {
		db = util.getWritableDatabase();
	}

	public void CerrarDB() {
		db.close();
	}

}
